django-commons / drf-excel

An XLSX spreadsheet renderer for Django REST Framework.
BSD 3-Clause "New" or "Revised" License
217 stars 40 forks source link

List of str is incorrectly prepped using json.dumps on newer Python version #84

Closed melvinkcx closed 4 months ago

melvinkcx commented 4 months ago

If you have a list of strings as value, the XLSXListField incorrectly preps it using json.dumps().

I believe this is not an intended behaviour, judging from the code comments.

This probably has to do with the fact that str is also an Iterable in newer versions of Python.

Screenshot 2024-06-21 at 3 01 14 PM

Screenshot 2024-06-21 at 3 05 58 PM

One potential solution that I found is:

https://stackoverflow.com/a/44328500/10955067


Workaround

Use xlsx_custom_mappings:

xlsx_custom_mappings = {
        col: lambda value: ", ".join(map(str, value))
        for col in [
            "col_1", "col_2", "col_3
        ]
    }
rptmat57 commented 4 months ago

good catch

melvinkcx commented 4 months ago

Thanks for the quick fix! Would it be possible to get it released soon?

FlipperPA commented 4 months ago

@melvinkcx @rptmat57 I can actually get this published today, since I'm at the Wagtail Space sprints.

FlipperPA commented 4 months ago

@rptmat57 @melvinkcx I've published as version 2.4.1 with a few bug fixes and... a long overdue upgrade to pyproject.toml!

melvinkcx commented 4 months ago

Thanks for the quick action, much appreciated!