-
-
Notifications
You must be signed in to change notification settings - Fork 930
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add escape hatch for custom JSON serialization #1955
Conversation
c7451cd
to
976fcc7
Compare
@vlindhol see lint errors please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linting/pre-commit fails
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linting/pre-commit fails
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, didn't see that one! I thought CI looked green 😅 Manually ran all CI commands in |
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 usingthe
encoder
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 wouldactivate it). If
decoder
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.