-
-
Notifications
You must be signed in to change notification settings - Fork 209
[change:radius] Replace third-party JSONField with Django built-in JSONField #619
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
base: master
Are you sure you want to change the base?
[change:radius] Replace third-party JSONField with Django built-in JSONField #619
Conversation
a9ad394 to
998b688
Compare
a0d7e52 to
21b4925
Compare
665a8b5 to
fa44638
Compare
|
@nemesifier kindly review |
nemesifier
left a comment
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.
Thanks @Eeshu-Yadav, see my comments below.
| name="user_credentials", | ||
| field=models.JSONField(blank=True, null=True, verbose_name="PDF"), | ||
| ), | ||
| migrations.RunPython( |
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.
Data migrations need to be executed in a dedicated migration file, please refer to https://stackoverflow.com/a/66799446 for more information.
| batch.user_credentials = json.loads(batch.user_credentials) | ||
| batch.save(update_fields=["user_credentials"]) | ||
| except (json.JSONDecodeError, TypeError): | ||
| # If it's already decoded or invalid JSON, skip it |
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.
It shouldn't fail. If it fails we must let it fail loudly, unless there can be failure which would be common and in that case we should catch the exception and resolve this automatically.
Why do you think it would fail here?
| to proper JSON objects for Django's built-in JSONField. | ||
| """ | ||
| RadiusBatch = apps.get_model("openwisp_radius", "RadiusBatch") | ||
| for batch in RadiusBatch.objects.exclude(user_credentials__isnull=True): |
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.
| for batch in RadiusBatch.objects.exclude(user_credentials__isnull=True): | |
| for batch in RadiusBatch.objects.exclude(user_credentials__isnull=True).iterator(): |
Not using iterator() may crash instances with large amount of rows and must be avoided.
fa44638 to
a763c2b
Compare
- Replaced third-party jsonfield.JSONField with Django's built-in models.JSONField in all model definitions - Updated RadiusBatch.prefix_add method to directly assign user_credentials list instead of using json.dumps() - Added migration 0043 to replace JSONField in model definitions - Added migration 0044 to convert existing double-encoded JSON data in user_credentials field (data migration in separate file) - Used .iterator() in data migration for memory efficiency - Removed jsonfield dependency from setup.py - Updated test migrations to use Django's JSONField - Removed unused json import Closes openwisp#600
a763c2b to
ba82cd9
Compare
|
@nemesifier kindly review |
Checklist
Reference to Existing Issue
Closes #600.
Description of Changes
This PR replaces the third-party
jsonfieldlibrary with Django's built-in JSONField. The third-party JSONField library hasn't received updates in 5 years, while Django's built-in JSONField is now mature and actively maintained.Changes Made:
from jsonfield import JSONFieldwithfrom django.db.models import JSONFieldin modelsRadiusBatch.user_credentialsandOrganizationRadiusSettings.sms_meta_datafields"jsonfield~=3.1.0"dependency from setup.py0041_replace_jsonfield_with_django_builtin.pyto handle field type transitionTesting: