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

Django 4.1 compatibility #434

Open
gabn88 opened this issue Dec 5, 2022 · 8 comments
Open

Django 4.1 compatibility #434

gabn88 opened this issue Dec 5, 2022 · 8 comments

Comments

@gabn88
Copy link
Contributor

gabn88 commented Dec 5, 2022

The requirement of the third party jsonfield does not play nice with the upgrade to Django 4.1.

I open this issue, since I think jsonfield can be removed in favor of the default django JSONfield. What do you think?

@selwin
Copy link
Collaborator

selwin commented Dec 6, 2022

I'm ok with this. Ideally we can do this in a backwards compatible way. Mind opening a PR for this?

@selwin
Copy link
Collaborator

selwin commented Dec 6, 2022

@gabn88 do you mind taking a look at this PR? #414

This PR also replaces jsonfield with Django's built in JSONField.

@gabn88
Copy link
Contributor Author

gabn88 commented Jan 24, 2023

@selwin

I have seen multiple packages replace jsonfield.JSONField to models.JSONField (from django 3.1+). AFAIK it works fine, but it didn't test it thoroughly. Backwards-compatible shouldn't be a big problem, as Django 3.1 is already not receiving LTS anymore, and from django 3.1 onwards models.JSONField exists. As long as the old data from jsonfield is compatible.

EDIT: I've digged deeper into it and the encoder of the current implementation is here: https://github.com/rpkilby/jsonfield/blob/master/src/jsonfield/encoder.py It is different from this implementation, but since we are talking here about headers and context here, whereby headers are strings anyway.

I can see it go wrong for the context. Ideally, we would copy-paste the encoder code and use it as encoder/decoder on the JSONfield. That way it will be 100% compatible. Otherwise old emails might not render correctly (when encoding/decoding dates or datetimes, for example).

@selwin
Copy link
Collaborator

selwin commented Jan 25, 2023 via email

@petrprikryl
Copy link
Contributor

I can see it go wrong for the context. Ideally, we would copy-paste the encoder code and use it as encoder/decoder on the JSONfield. That way it will be 100% compatible. Otherwise old emails might not render correctly (when encoding/decoding dates or datetimes, for example).

Dates/datetimes are serialized into strings too. So the rendering will be using same data (context) after migration. If you look at https://github.com/rpkilby/jsonfield/blob/3.1.0/src/jsonfield/fields.py#L17 you will see that there isn't custom decoder class so date/datetimes aren't converted to Python objects in json.loads step.

@selwin
Copy link
Collaborator

selwin commented May 16, 2023

I have decided on the way forward. The safest way would be to add a new JSON column using Django's built in JSONField and keep backward compatibility for a while before we can eventually drop the old column.

@gabn88
Copy link
Contributor Author

gabn88 commented May 16, 2023

This is actually a good idea. Let's do that as it gives people a time frame to do the migration themselves.
I assume you would include a setting which column to use, where the default in this release is the old column and in the next major release will be the new column?

@selwin
Copy link
Collaborator

selwin commented May 16, 2023 via email

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

No branches or pull requests

3 participants