openwisp-controller icon indicating copy to clipboard operation
openwisp-controller copied to clipboard

[models] Replace thirdparty JSONField with Django built-in JSONField

Open Eeshu-Yadav opened this issue 4 months ago • 0 comments

Checklist

  • [x] I have read the OpenWISP Contributing Guidelines.
  • [x] 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 #1061.

Description of Changes

This PR replaces the third-party jsonfield package with Django's built-in JSONField across all OpenWISP controller models to modernize the codebase and remove dependency on an unmaintained package.

Changes Made:

  • Updated 6 model files to use django.db.models.JSONField instead of third-party jsonfield.JSONField:

    • openwisp_controller/config/base/base.py
    • openwisp_controller/config/base/config.py
    • openwisp_controller/config/base/device_group.py
    • openwisp_controller/config/base/multitenancy.py
    • openwisp_controller/config/base/template.py
    • openwisp_controller/connection/base/models.py
  • Created 2 migration files to safely alter field types:

    • openwisp_controller/config/migrations/0061_replace_jsonfield_with_django_builtin.py
    • openwisp_controller/connection/migrations/0010_replace_jsonfield_with_django_builtin.py
  • Removed jsonfield-specific parameters (load_kwargs, dump_kwargs) that are not supported by Django's JSONField

  • Fixed code quality issues by removing unused imports and duplicate imports

Technical Details:

  • Django's JSONField handles JSON serialization internally without needing external parameters
  • The load_kwargs={"object_pairs_hook": collections.OrderedDict} is no longer needed as Python 3.7+ dicts maintain insertion order
  • The dump_kwargs={"indent": 4} formatting should be handled at the serialization/display layer, not the model level
  • All existing JSON data remains compatible and accessible

Eeshu-Yadav avatar Aug 12 '25 08:08 Eeshu-Yadav