Skip to content
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

Give user registered types priority when encoding / decoding JSON #2188

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

soceanainn
Copy link

@soceanainn soceanainn commented Nov 7, 2024

User registered types should take priority over default types in Kombu.

Although users can currently override the encoder/decoder for a Kombu registered type by calling register_type (for example calling register_type(Decimal, ...) in their own code), this doesn't work well when it comes to subclassing. If users currently need to pass subclasses of any Celery registered types (datetime, date, time, Decimal or UUID) they would be forced to either:

  1. Override implementation of superclass with a subclass aware encoder / decoder implementation, or
  2. Access the 'protected' _encoders dictionary in the Kombu json module, pop the value for the superclass, add their subclass, and then re-add the superclass.

By separating user registered types and Kombu registered types into separate dictionaries, we can always give priority to user registered types instead, which simplifies this process for users (although technically it is a breaking change from existing behaviour).

Solves #1895

Copy link

codecov bot commented Nov 7, 2024

Codecov Report

Attention: Patch coverage is 95.65217% with 1 line in your changes missing coverage. Please review.

Project coverage is 81.50%. Comparing base (6c00d9a) to head (2066474).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
kombu/utils/json.py 95.65% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2188      +/-   ##
==========================================
+ Coverage   81.49%   81.50%   +0.01%     
==========================================
  Files          77       77              
  Lines        9509     9520      +11     
  Branches     1148     1153       +5     
==========================================
+ Hits         7749     7759      +10     
  Misses       1569     1569              
- Partials      191      192       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@soceanainn soceanainn force-pushed the seamus/give-custom-json-encoders-priority branch from 52b2f86 to 247cf3e Compare November 7, 2024 14:45
@thedrow
Copy link
Member

thedrow commented Nov 13, 2024

@soceanainn Can you please check why the tests are failing before I review?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants