django-rest-framework-csv icon indicating copy to clipboard operation
django-rest-framework-csv copied to clipboard

Bug: after data has been flattened, and header has been explicitely set, the CSV output is missing the flattened data

Open emammadov-cpr opened this issue 4 years ago • 0 comments

Setup: CSVRenderer.header is set. For example renderer.header = ['a', 'b'] And the data contains

data = [{
   'a': 1,
   'b': [                      << --- this is a list of dictionaries
   {
        'c': 2
   },
   {
        'c': 3
   }]
}]

The data would get flattened producing

data = [{
   'a': 1,
  'b.0.c": 2,
  "b.1.c": 3
}]

The CSV output file would contain two columns a,b. The value for a would be 1. The value for b would be missing from CSV. The expected output in CSV was three columns a, b.0.c, b.1.c with their respective values.

Using CSVStreamingRenderer, but I believe this doesn't matter and would apply to CSVRenderer, too.

In the case when CSVRenderer.header is not set, the default behaviour gets the keys after flattening the data, therefore it works in that case.

emammadov-cpr avatar Sep 20 '21 18:09 emammadov-cpr