Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom field with trailing white space unable to import #15082

Closed
ponchofiesta opened this issue Feb 8, 2024 · 7 comments · Fixed by #16203
Closed

Custom field with trailing white space unable to import #15082

ponchofiesta opened this issue Feb 8, 2024 · 7 comments · Fixed by #16203
Assignees
Labels
severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@ponchofiesta
Copy link

Deployment Type

Self-hosted

NetBox Version

v3.6.9

Python Version

3.8

Steps to Reproduce

  1. Create custom field for Virtual machine with multi selection
  2. One value has a trailing whitespace, e.g. "bla "
  3. Try to import this value via CSV:
id,cf_CustField
123,bla

This won't work too:

id,cf_CustField
123,"bla "

But this works:

id,cf_CustField
123,"bla ,anotherBla"

Expected Behavior

It will get imported

Suggestion: By default remove any leading and trailing white spaces form field values.

Observed Behavior

Error: "Record 1 cf_CustField: Select a valid choice. bla is not one of the available choices."

@ponchofiesta ponchofiesta added the type: bug A confirmed report of unexpected behavior in the application label Feb 8, 2024
@jeremystretch
Copy link
Member

Thank you for opening a bug report. I was unable to reproduce the reported behavior on NetBox v3.7.1. Please re-confirm the reported behavior on the current stable release and adjust your post above as necessary. Remember to provide detailed steps that someone else can follow using a clean installation of NetBox to reproduce the issue. Remember to include the steps taken to create any initial objects or other data.

@jeremystretch jeremystretch added the status: revisions needed This issue requires additional information to be actionable label Feb 8, 2024
@sleepinggenius2
Copy link
Contributor

I would be extremely careful about automatically stripping leading and trailing white space in imports. There is already a pretty frustrating bug when importing tab-separated data where the input gets trimmed and it breaks on the last row if it has legitimate trailing tabs for empty columns. I think the expectation should be that data entered during a bulk import has already been adequately cleaned beforehand.

@ponchofiesta
Copy link
Author

I'm not sure if the problem was understand correctly. Wgen defining the custom field, one of the possible values has a trailung blank. And it is not possbile to import this value using CSV import. It looks like Netbox already drops the blank on an import and therefore the importvalue doesn't match the custom field value.

@ponchofiesta
Copy link
Author

I analyzed the source code a little and I think I found the cause. The csv reader doesn't drop the blank values but Netbox does:
https://github.com/netbox-community/netbox/blob/develop/netbox/utilities/forms/utils.py#L237

And if I understand the code correctly, the CustomFieldChoices are not striped.

@sleepinggenius2
Copy link
Contributor

Suggestion: By default remove any leading and trailing white spaces form field values.

That made it sound like you were saying that the fields should be stripped in the CSV import, not on the custom field choice value. It sounds though like the CSV fields are being stripped, while the custom field choice values are not. So, is this bug actually for the custom field choice values not being stripped? If so, that was extremely unclear from the initial bug report, but it does make sense to me.

That being said, I also find it kind of surprising and a bit unintuitive from a UX standpoint that a quoted value in the CSV import would still strip white space. I might understand that if the field was just left raw and unquoted, but maybe that nuance of unquoting is handled by the CSV library and the NetBox code is not able to make that distinction.

@ponchofiesta
Copy link
Author

ponchofiesta commented Feb 23, 2024

@jeremystretch I verified it with current Netbox version using Docker [v3.7.3-2.8.0].

Steps:

  • Created Super user, Dummy Cluster, VM, Custom field
  • Create Custom Field Choice Set with these exact "Extra Choices" (note the " " after "Space"):
    Space 
    NoSpace
    AnotherOne
    
  • Create the Custom Field for VMs using the Custom Field Choice Set
  • Try to import this data to the VM via CSV. All of these variants will fail:
    Without extra space:
    id,cf_TestField
    1,Space
    
    With extra space after "Space":
    id,cf_TestField
    1,Space 
    
    With extra space and quotes:
    id,cf_TestField
    1,"Space "
    

And this happens because Netbox trims import data fields but not field choice values. I'd say trimming import data is incorrect behavior.

@jeremystretch jeremystretch added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation severity: low Does not significantly disrupt application functionality, or a workaround is available and removed status: revisions needed This issue requires additional information to be actionable labels May 13, 2024
@Julio-Oliveira-Encora
Copy link
Contributor

Could you please assign it to me?

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation labels May 17, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants