-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Description
I'm currently trying to import our existing list of devices into snipeit. After creating some custom fields and running the importer I noticed that for some
reason some of the assets failed validation while others passed for seemingly no reason.
After reducing my test case I got it down to the following CSV, where the first item fails validation and the second one gets imported successfully
Asset Tag,Category,NumberField,Location,Company,Model Name,Item Name
10,mycategory,0,Room1,mycompany,PCModel,Test1
11,mycategory,1,Room1,mycompany,PCModel,Test2
NumberField is a custom Field that is marked as required for PCModel
How to reproduce
- Create a custom field of numeric type (NumberField)
- Add it to a fieldset and mark it as 'required'
- Create a corresponding Asset Model using that fieldset and try to import the CSV using
php artisan snipeit:import ...
The first item will fail validation
SnipeIT Version
v8.1.18 build 18876
PHP Version
8.3.6
After poking around a bit in the import code I noticed the following in app/Importer/AssetImporter.php
snipe-it/app/Importer/AssetImporter.php
Lines 47 to 58 in 1eae5d1
| if ($customFieldValue) { | |
| if ($customField->field_encrypted == 1) { | |
| $this->item['custom_fields'][$customField->db_column_name()] = Crypt::encrypt($customFieldValue); | |
| $this->log('Custom Field '.$customField->name.': '.Crypt::encrypt($customFieldValue)); | |
| } else { | |
| $this->item['custom_fields'][$customField->db_column_name()] = $customFieldValue; | |
| $this->log('Custom Field '.$customField->name.': '.$customFieldValue); | |
| } | |
| } else { | |
| // Clear out previous data. | |
| $this->item['custom_fields'][$customField->db_column_name()] = null; | |
| } |
It seems the conditional might interpret zero numeric values as false and just null them, which then causes the Asset to fail validation later on?
I'm not familiar enough with the codebase to know if this would be the place to fix this, but changing the conditional to use an
!is_null($customFieldValue) check allowed all my items to import successfully.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status