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

Incorrect import CSV with multiline values #7780

Closed
seros1521 opened this issue Nov 9, 2021 · 2 comments
Closed

Incorrect import CSV with multiline values #7780

seros1521 opened this issue Nov 9, 2021 · 2 comments
Assignees
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@seros1521
Copy link
Contributor

NetBox version

v3.0.8

Python version

3.7

Steps to Reproduce

1.open the CSV file import page for Sites
2.import a CSV file with the following content:

name,slug,status,comments
name1,slug1,active,"multiline
comment"

Expected Behavior

The "comments" field is expected to preserve the line break.

Observed Behavior

When importing a file, the line break in the multi-line comments field disappears.
When importing through the "CSV Data" form, the import is correct, the line feed is preserved.

@seros1521 seros1521 added the type: bug A confirmed report of unexpected behavior in the application label Nov 9, 2021
@seros1521
Copy link
Contributor Author

Different behavior occurs due to different way of processing input data:

reader = csv.reader(StringIO(value.strip()))

and
reader = csv.reader(csv_str.splitlines())

Demo:

>>> import csv
>>> from io import StringIO
>>> s="""name,slug,status,comments
... name1,slug1,active,"multiline
... comment"
... """
>>> 
>>> [i for i in s.splitlines()]
['name,slug,status,comments', 'name1,slug1,active,"multiline', 'comment"']
>>> 
>>> [i for i in StringIO(s)]
['name,slug,status,comments\n', 'name1,slug1,active,"multiline\n', 'comment"\n']
>>> 
>>> [i for i in csv.reader(s.splitlines())]
[['name', 'slug', 'status', 'comments'], ['name1', 'slug1', 'active', 'multilinecomment']]
>>> 
>>> [i for i in csv.reader(StringIO(s))]
[['name', 'slug', 'status', 'comments'], ['name1', 'slug1', 'active', 'multiline\ncomment']]
>>> 

@DanSheps
Copy link
Member

DanSheps commented Nov 9, 2021

Can you comment your test cases?

To clarify, StringIO is the desired import right?

When importing a file, the line break in the multi-line comments field disappears.
When importing through the "CSV Data" form, the import is correct, the line feed is preserved.

Could you also clarify this? What is the case for each?

@DanSheps DanSheps added the status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation label Nov 9, 2021
@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 Nov 9, 2021
@jeremystretch jeremystretch self-assigned this Nov 9, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

3 participants