Closed vlindhol closed 3 months ago
@vlindhol see lint errors please
https://github.com/celery/kombu/actions/runs/8262054534/job/22602777695#step:7:1
Sorry, didn't see that one! I thought CI looked green 😅 Manually ran all CI commands in ci.yaml
now, and pushed fixes.
Thank you!
Summary
As reported in multiple issues (#1841, #1821, #1787, #1749), it was a surprising breaking change when some Python types became wrapped in a
{ "__type__": ..., "__value__": ...}
envelope in 5.3.0 and subsequently deserialized back into the native types.Using
kombu.util.json.register_type()
one could at least avoid e.g.datetime
becoming deserialized into adatetime
and keep it as astr
as in <5.3.0, but it's currently impossible to get rid of the envelope itself.This PR changes
register_type()
to acceptmarker=None
, which signals that the JSON encoder should only transform the value using theencoder
arg, but should not stick the result in an envelope.A side-effect of this is that the decoder thus becomes unnecessary to specify (since there is no
__type__
in the resulting JSON that would activate it). Ifdecoder
is omitted, default to a simple identity function.This way one can replicate the behavior of pre-5.3.0 fairly well by overriding the default-registered types as follows:
Tests
Added some unit tests around
register_type()
, which were completely missing before. Also tests the new functionality.