From 8d7c7139606881531093642f2c164f637824d1b4 Mon Sep 17 00:00:00 2001 From: Ehsan Mohamed Date: Wed, 9 Jul 2025 00:15:56 +0530 Subject: [PATCH] [change] Switched third-party JSONField to built-in JSONField #673 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaced all uses of third-party with Django’s built-in and added corresponding migrations. Django applies the type conversion automatically using the appropriate SQL command, ensuring that existing data remains safe. Fixes #673 --- openwisp_monitoring/check/base/models.py | 7 +----- .../migrations/0012_alter_check_params.py | 23 +++++++++++++++++ openwisp_monitoring/monitoring/base/models.py | 9 ++----- ...etric_extra_tags_alter_metric_main_tags.py | 25 +++++++++++++++++++ .../migrations/0004_alter_check_params.py | 23 +++++++++++++++++ ...etric_extra_tags_alter_metric_main_tags.py | 25 +++++++++++++++++++ 6 files changed, 99 insertions(+), 13 deletions(-) create mode 100644 openwisp_monitoring/check/migrations/0012_alter_check_params.py create mode 100644 openwisp_monitoring/monitoring/migrations/0013_alter_metric_extra_tags_alter_metric_main_tags.py create mode 100644 tests/openwisp2/sample_check/migrations/0004_alter_check_params.py create mode 100644 tests/openwisp2/sample_monitoring/migrations/0005_alter_metric_extra_tags_alter_metric_main_tags.py diff --git a/openwisp_monitoring/check/base/models.py b/openwisp_monitoring/check/base/models.py index ed1af76f4..100633bf2 100644 --- a/openwisp_monitoring/check/base/models.py +++ b/openwisp_monitoring/check/base/models.py @@ -1,12 +1,9 @@ -from collections import OrderedDict - from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.models import ContentType from django.db import models from django.utils.functional import cached_property from django.utils.module_loading import import_string from django.utils.translation import gettext_lazy as _ -from jsonfield import JSONField from openwisp_utils.base import TimeStampedEditableModel @@ -37,13 +34,11 @@ class AbstractCheck(TimeStampedEditableModel): db_index=True, max_length=128, ) - params = JSONField( + params = models.JSONField( _("parameters"), default=dict, blank=True, help_text=_("parameters needed to perform the check"), - load_kwargs={"object_pairs_hook": OrderedDict}, - dump_kwargs={"indent": 4}, ) class Meta: diff --git a/openwisp_monitoring/check/migrations/0012_alter_check_params.py b/openwisp_monitoring/check/migrations/0012_alter_check_params.py new file mode 100644 index 000000000..be126d62e --- /dev/null +++ b/openwisp_monitoring/check/migrations/0012_alter_check_params.py @@ -0,0 +1,23 @@ +# Generated by Django 5.2.4 on 2025-07-08 16:30 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("check", "0011_check_active_object_checks_idx"), + ] + + operations = [ + migrations.AlterField( + model_name="check", + name="params", + field=models.JSONField( + blank=True, + default=dict, + help_text="parameters needed to perform the check", + verbose_name="parameters", + ), + ), + ] diff --git a/openwisp_monitoring/monitoring/base/models.py b/openwisp_monitoring/monitoring/base/models.py index 7c5c7ad92..47350d0d1 100644 --- a/openwisp_monitoring/monitoring/base/models.py +++ b/openwisp_monitoring/monitoring/base/models.py @@ -16,7 +16,6 @@ from django.db import IntegrityError, models from django.utils import timezone from django.utils.translation import gettext_lazy as _ -from jsonfield import JSONField from openwisp_notifications.signals import notify from pytz import timezone as tz from pytz import utc @@ -91,20 +90,16 @@ class AbstractMetric(TimeStampedEditableModel): ) object_id = models.CharField(max_length=36, db_index=True, blank=True, null=True) content_object = GenericForeignKey("content_type", "object_id") - main_tags = JSONField( + main_tags = models.JSONField( _("main tags"), default=dict, blank=True, - load_kwargs={"object_pairs_hook": OrderedDict}, - dump_kwargs={"indent": 4}, db_index=True, ) - extra_tags = JSONField( + extra_tags = models.JSONField( _("extra tags"), default=dict, blank=True, - load_kwargs={"object_pairs_hook": OrderedDict}, - dump_kwargs={"indent": 4}, ) # NULL means the health has yet to be assessed is_healthy = models.BooleanField(default=None, null=True, blank=True, db_index=True) diff --git a/openwisp_monitoring/monitoring/migrations/0013_alter_metric_extra_tags_alter_metric_main_tags.py b/openwisp_monitoring/monitoring/migrations/0013_alter_metric_extra_tags_alter_metric_main_tags.py new file mode 100644 index 000000000..1dd4d37af --- /dev/null +++ b/openwisp_monitoring/monitoring/migrations/0013_alter_metric_extra_tags_alter_metric_main_tags.py @@ -0,0 +1,25 @@ +# Generated by Django 5.2.4 on 2025-07-08 16:30 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("monitoring", "0012_migrate_signal_metrics"), + ] + + operations = [ + migrations.AlterField( + model_name="metric", + name="extra_tags", + field=models.JSONField(blank=True, default=dict, verbose_name="extra tags"), + ), + migrations.AlterField( + model_name="metric", + name="main_tags", + field=models.JSONField( + blank=True, db_index=True, default=dict, verbose_name="main tags" + ), + ), + ] diff --git a/tests/openwisp2/sample_check/migrations/0004_alter_check_params.py b/tests/openwisp2/sample_check/migrations/0004_alter_check_params.py new file mode 100644 index 000000000..06e4a6985 --- /dev/null +++ b/tests/openwisp2/sample_check/migrations/0004_alter_check_params.py @@ -0,0 +1,23 @@ +# Generated by Django 5.2.4 on 2025-07-08 17:37 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("sample_check", "0003_add_check_inline_permissions"), + ] + + operations = [ + migrations.AlterField( + model_name="check", + name="params", + field=models.JSONField( + blank=True, + default=dict, + help_text="parameters needed to perform the check", + verbose_name="parameters", + ), + ), + ] diff --git a/tests/openwisp2/sample_monitoring/migrations/0005_alter_metric_extra_tags_alter_metric_main_tags.py b/tests/openwisp2/sample_monitoring/migrations/0005_alter_metric_extra_tags_alter_metric_main_tags.py new file mode 100644 index 000000000..90ee7151b --- /dev/null +++ b/tests/openwisp2/sample_monitoring/migrations/0005_alter_metric_extra_tags_alter_metric_main_tags.py @@ -0,0 +1,25 @@ +# Generated by Django 5.2.4 on 2025-07-08 17:37 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("sample_monitoring", "0004_alter_metric_field_name"), + ] + + operations = [ + migrations.AlterField( + model_name="metric", + name="extra_tags", + field=models.JSONField(blank=True, default=dict, verbose_name="extra tags"), + ), + migrations.AlterField( + model_name="metric", + name="main_tags", + field=models.JSONField( + blank=True, db_index=True, default=dict, verbose_name="main tags" + ), + ), + ]