Skip to content

Conversation

@Eeshu-Yadav
Copy link
Contributor

Checklist

  • I have read the OpenWISP Contributing Guidelines.
  • I have manually tested the changes proposed in this pull request.
  • I have written new test cases for new code and/or updated existing tests for changes to existing code.
  • I have updated the documentation.

Reference to Existing Issue

Closes #600.

Description of Changes

This PR replaces the third-party jsonfield library 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:

  • Replaced from jsonfield import JSONField with from django.db.models import JSONField in models
  • Updated RadiusBatch.user_credentials and OrganizationRadiusSettings.sms_meta_data fields
  • Removed "jsonfield~=3.1.0" dependency from setup.py
  • Added migration 0041_replace_jsonfield_with_django_builtin.py to handle field type transition
  • Updated test migrations to use Django's JSONField

Testing:

  • All existing tests pass with the new implementation
  • Verified RadiusBatch and SMS metadata functionality
  • Migration tested without data loss

@Eeshu-Yadav Eeshu-Yadav force-pushed the issues/600-replace-jsonfield-clean branch 2 times, most recently from a9ad394 to 998b688 Compare August 22, 2025 22:21
@Eeshu-Yadav Eeshu-Yadav force-pushed the issues/600-replace-jsonfield-clean branch 2 times, most recently from a0d7e52 to 21b4925 Compare October 9, 2025 17:27
@Eeshu-Yadav Eeshu-Yadav force-pushed the issues/600-replace-jsonfield-clean branch 4 times, most recently from 665a8b5 to fa44638 Compare October 22, 2025 18:37
@Eeshu-Yadav
Copy link
Contributor Author

@nemesifier kindly review

@coveralls
Copy link

coveralls commented Oct 22, 2025

Coverage Status

coverage: 97.268% (-0.001%) from 97.269%
when pulling ba82cd9 on Eeshu-Yadav:issues/600-replace-jsonfield-clean
into 38ee442 on openwisp:master.

Copy link
Member

@nemesifier nemesifier left a 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(
Copy link
Member

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
Copy link
Member

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):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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.

@Eeshu-Yadav Eeshu-Yadav force-pushed the issues/600-replace-jsonfield-clean branch from fa44638 to a763c2b Compare November 18, 2025 15:50
- 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
@Eeshu-Yadav Eeshu-Yadav force-pushed the issues/600-replace-jsonfield-clean branch from a763c2b to ba82cd9 Compare November 30, 2025 13:28
@Eeshu-Yadav
Copy link
Contributor Author

@nemesifier kindly 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.

[change:radius] Replace thirdparty JSONField with Django built in JSONField

3 participants