Export Assets CSV breaking on Notes field lines

While working on an entity tree project for my FarmOS, I noticed that exporting to CSV from the asset view, breaks a little.
This might be useful to whoever knows where the issue is, or if anyone else is experiencing this.

To recreate, visit your /taxonomy/term/11/assets (or whatever specific set of assets)
Select * or specific records
At the bottom, Export CSV of the selected items.

Result: CSV includes records, with lines ‘newlined’ by each line in the ‘notes’ field.
It produces a CSV with more lines than records, as each line in the note field, is a new line in the CSV. Something like the attachment.

Hope this is useful.

1 Like

I believe this is the expected behavior, and is valid CSV formatting. The “Notes” field in this case is wrapped in double quotes, so any CSV parsing code should recognize that the line breaks are inside the cell, and are not denoting a new row.

For context, farmOS doesn’t make this decision itself. It uses the CSV Serialization module, which in turn uses the LeagueCSV PHP library. All farmOS does is create an array of column data that it passes to these libraries, which then handle the formatting per CSV standards.

If you are writing any custom code to parse these CSVs, you just need to make sure you’re using an appropriate library that knows how to follow the same standard while it is reading each row.

I will do some more thorough investigation. It definitely splits the lines on ‘.’ or newline inside the notes, even though the field separator is ,
And then, in some fields ‘sex’ is omitted, even though all the animals have all fields set (data sanitation confirmed).
But I see that lib now, thank you. Will look into it deeper

1 Like

Oh maybe I misunderstood. In the screenshot you shared it looks like it was only creating a new line when there was a newline in the Notes field. I don’t see what you mean about . characters.

Hmm this may be related to a bug we found recently and are thinking about how to solve: Export CSV on all assets/logs chooses header columns from the first asset/log in the list · Issue #805 · farmOS/farmOS · GitHub

Did you export from a list that includes multiple types of assets? If so, then you may experience that bug. If you exported from a list of ONLY animal assets, then it might be something else going on.