You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Handle serializing dicts with ints and strings #3380
Maybe it was a mistake to set sort_keys=True. This is the behavior of orjson, and at the time it seemed reasonable to align the output across json engines 🙂
I don' t see a way to address this from within our custom PlotlyJSONEncoder, so I see two options:
Remove sort_keys=True, adjusting tests to accept that the json engines will not produce identical results
Try json.dumps and catch the exception. If the exception is raised, clone the input dict and modify it to convert non-string keys to strings before running json.dumps again.
Hmmm yeah, it kinda feels like "Remove sort_keys=True, adjusting tests to accept that the json engines will not produce identical results" is the safer route... basically getting folks to opt-in to orjson and any related constraints. Sorry!
Activity
nicolaskruchten commentedon Sep 13, 2021
@jonmmease is this something you could take a look at please? There's going to be some ambiguity if the same dict has
1and"1"as keys...nicolaskruchten commentedon Sep 13, 2021
Admittedly, that's an ambiguity that JSON imposes.
jonmmease commentedon Sep 14, 2021
FWIW, this can be reproduced without plotly.py
The reason that we're hitting this now is that we switched to using
sort_keys=Trueduring theorjsonrefactor.As @chriddyp pointed out, there is a 2+ year long discussion in https://bugs.python.org/issue25457 on whether this is actually a bug in the Python 3 json module.
Maybe it was a mistake to set
sort_keys=True. This is the behavior of orjson, and at the time it seemed reasonable to align the output across json engines 🙂I don' t see a way to address this from within our custom
PlotlyJSONEncoder, so I see two options:sort_keys=True, adjusting tests to accept that the json engines will not produce identical resultsjson.dumpsand catch the exception. If the exception is raised, clone the input dict and modify it to convert non-string keys to strings before runningjson.dumpsagain.Thoughts @nicolaskruchten ?
nicolaskruchten commentedon Sep 15, 2021
Hmmm yeah, it kinda feels like "Remove sort_keys=True, adjusting tests to accept that the json engines will not produce identical results" is the safer route... basically getting folks to opt-in to
orjsonand any related constraints. Sorry!