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 1 commit 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.51%. Comparing base (c5e25d2) to head (7a20cbd).
Report is 1 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.50%   81.51%   +0.01%     
==========================================
  Files          77       77              
  Lines        9522     9533      +11     
  Branches     1151     1156       +5     
==========================================
+ Hits         7761     7771      +10     
  Misses       1569     1569              
- Partials      192      193       +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
Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix the lint errors as well

@soceanainn soceanainn force-pushed the seamus/give-custom-json-encoders-priority branch 2 times, most recently from e9cfe80 to 21430db Compare November 18, 2024 21:41
@soceanainn soceanainn requested a review from auvipy November 18, 2024 21:42
Copy link
Member

@Nusnus Nusnus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I briefly reviewed the PR and it looks nice but I wonder if anything might break due to the split, even though it makes sense.

@Nusnus Nusnus force-pushed the seamus/give-custom-json-encoders-priority branch from 21430db to b3d4bb7 Compare December 1, 2024 23:28
@Nusnus Nusnus force-pushed the seamus/give-custom-json-encoders-priority branch from b3d4bb7 to 7a20cbd Compare December 26, 2024 22:42
@auvipy
Copy link
Member

auvipy commented Dec 28, 2024

I briefly reviewed the PR and it looks nice but I wonder if anything might break due to the split, even though it makes sense.

technically the change is a breaking change

@auvipy
Copy link
Member

auvipy commented Dec 29, 2024

we have to release in in a new major version like 5.5/5.6

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.

3 participants