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

models: Use Django native JSONField #465

Merged
merged 1 commit into from
Jun 27, 2023

Conversation

nijel
Copy link
Member

@nijel nijel commented Jun 10, 2023

Proposed changes

It was introduced in Django 3.1 and social_django already requires Django 3.2.

Fixes #464
Fixes #209

Types of changes

Please check the type of change your PR introduces:

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (PEP8, lint, formatting, renaming, etc)
  • Refactoring (no functional changes, no api changes)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Build related changes (build process, tests runner, etc)
  • Other (please describe):

Checklist

Put an x in the boxes that apply. You can also fill these out after creating
the PR. If you're unsure about any of them, don't hesitate to ask. We're here to
help! This is simply a reminder of what we are going to look for before merging
your code.

  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works

Other information

Any other information that is important to this PR such as screenshots of how
the component looks before and after the change.

@nijel nijel requested a review from a team June 10, 2023 07:21
@codecov
Copy link

codecov bot commented Jun 10, 2023

Codecov Report

Merging #465 (191c1c9) into master (8d0a205) will increase coverage by 0.16%.
The diff coverage is 54.54%.

@@            Coverage Diff             @@
##           master     #465      +/-   ##
==========================================
+ Coverage   93.66%   93.83%   +0.16%     
==========================================
  Files          35       39       +4     
  Lines        1121     1119       -2     
  Branches      130      130              
==========================================
  Hits         1050     1050              
+ Misses         45       44       -1     
+ Partials       26       25       -1     
Flag Coverage Δ
unittests 93.83% <54.54%> (+0.16%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
social_django/fields.py 30.00% <33.33%> (-13.34%) ⬇️
...ocial_django/migrations/0013_migrate_extra_data.py 33.33% <33.33%> (ø)
...o/migrations/0012_usersocialauth_extra_data_new.py 100.00% <100.00%> (ø)
...igrations/0014_remove_usersocialauth_extra_data.py 100.00% <100.00%> (ø)
...rename_extra_data_new_usersocialauth_extra_data.py 100.00% <100.00%> (ø)
social_django/models.py 100.00% <100.00%> (ø)

It was introduced in Django 3.1 and social_django already requires
Django 3.2.

Fixes python-social-auth#464
Fixes python-social-auth#209
@ShaheedHaque
Copy link

I have tested the branch. First, I ran the old code and verified that the extra_data was a string:

>>> from social_django.models import UserSocialAuth
>>> UserSocialAuth.objects.all()[0].extra_data
'{"auth_time": 1686390682, "session_index": "_dWXC7z0-o8ffbl8Dm-bPV8B3bxVpeHvp", "name_id": "auth0|62ce80da6379e9972defbebe", "idp_name": "28361fbf-666b-4ae2-b5f1-0366258f78bc", "idp_display_name": "Acme - auth0.com", "idp_logo": "https://login.paiyroll.com/static/images/paiyroll.001.png"}'
>>> type(UserSocialAuth.objects.all()[0].extra_data)
<class 'str'>

I then ran the migrations from this commit, and the extra_data is now, correctly, a dict:

>>> from social_django.models import UserSocialAuth
>>> UserSocialAuth.objects.all()[0].extra_data
{'name_id': 'auth0|62ce80da6379e9972defbebe', 'idp_logo': 'https://login.paiyroll.com/static/images/paiyroll.001.png', 'idp_name': '28361fbf-666b-4ae2-b5f1-0366258f78bc', 'auth_time': 1686390682, 'session_index': '_dWXC7z0-o8ffbl8Dm-bPV8B3bxVpeHvp', 'idp_display_name': 'Acme - auth0.com'}
>>> type(UserSocialAuth.objects.all()[0].extra_data)
<class 'dict'>

Finally, I ran our system test which caught the issue, and it now passes.

So, this change LGTM: thanks!

@nijel nijel merged commit 6ee061b into python-social-auth:master Jun 27, 2023
@nijel nijel deleted the jsonfield branch June 27, 2023 13:10
@rib3
Copy link

rib3 commented Jul 26, 2023

Would it be possible to cut (and publish) a release with this change?

goneri added a commit to ansible/ansible-ai-connect-service that referenced this pull request Aug 29, 2023
- Upgrade social-auth-app-django to a pre-release of 5.2.0 that include
  python-social-auth/social-app-django#465
- Upgrade social-auth-core to match social-auth-app-django's requirements.
robinbobbitt pushed a commit to ansible/ansible-ai-connect-service that referenced this pull request Aug 29, 2023
- Upgrade social-auth-app-django to a pre-release of 5.2.0 that include
  python-social-auth/social-app-django#465
- Upgrade social-auth-core to match social-auth-app-django's requirements.
@parberge
Copy link

parberge commented Sep 4, 2023

Couldn't find any information about this in the release, so I'll ask here:

Does this mean we should remove SOCIAL_AUTH_JSONFIELD_ENABLED from settings if we update to 5.3.0?
Also I wonder if https://python-social-auth.readthedocs.io/en/latest/configuration/django.html#json-field-support should be updated as well?

I see 5.2.0 is still the "latest" according to releases here on github. But on pypi it's 5.3.0

@nijel
Copy link
Member Author

nijel commented Sep 4, 2023

Does this mean we should remove SOCIAL_AUTH_JSONFIELD_ENABLED from settings if we update to 5.3.0?

Once you upgrade, it is still used during the migration.

Also I wonder if https://python-social-auth.readthedocs.io/en/latest/configuration/django.html#json-field-support should be updated as well?

Yes it should, contributions are welcome.

I see 5.2.0 is still the "latest" according to releases here on github. But on pypi it's 5.3.0

I forgot to tick “Set as the latest release”, fixed now.

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