Skip to content

Conversation

Eeshu-Yadav
Copy link

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 #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

…penwisp#1061

Replaced jsonfield package's JSONField with Django's built-in JSONField
across all models to use the modern, maintained Django implementation.

Changes:
- Updated imports from 'jsonfield import JSONField' to 'django.db.models import JSONField'
- Removed jsonfield-specific parameters (load_kwargs, dump_kwargs) which are not needed
- Created migrations to alter field types while preserving data
- Removed unnecessary collections imports where no longer needed

Django's JSONField preserves the same data format and is backward compatible,
so no data migration is required. The built-in JSONField provides better
performance and is actively maintained as part of Django core.

Fixes openwisp#1061
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:controller] Replace thirdparty JSONField with Django built in JSONField
1 participant