Skip to content

Commit 3975f34

Browse files
committed
[change] Switched third-party JSONField to built-in JSONField #673
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
1 parent f4eca4a commit 3975f34

File tree

6 files changed

+99
-13
lines changed

6 files changed

+99
-13
lines changed

openwisp_monitoring/check/base/models.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
from collections import OrderedDict
2-
31
from django.contrib.contenttypes.fields import GenericForeignKey
42
from django.contrib.contenttypes.models import ContentType
53
from django.db import models
64
from django.utils.functional import cached_property
75
from django.utils.module_loading import import_string
86
from django.utils.translation import gettext_lazy as _
9-
from jsonfield import JSONField
107

118
from openwisp_utils.base import TimeStampedEditableModel
129

@@ -37,13 +34,11 @@ class AbstractCheck(TimeStampedEditableModel):
3734
db_index=True,
3835
max_length=128,
3936
)
40-
params = JSONField(
37+
params = models.JSONField(
4138
_("parameters"),
4239
default=dict,
4340
blank=True,
4441
help_text=_("parameters needed to perform the check"),
45-
load_kwargs={"object_pairs_hook": OrderedDict},
46-
dump_kwargs={"indent": 4},
4742
)
4843

4944
class Meta:
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 5.2.4 on 2025-07-08 16:30
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("check", "0011_check_active_object_checks_idx"),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name="check",
15+
name="params",
16+
field=models.JSONField(
17+
blank=True,
18+
default=dict,
19+
help_text="parameters needed to perform the check",
20+
verbose_name="parameters",
21+
),
22+
),
23+
]

openwisp_monitoring/monitoring/base/models.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from django.db import IntegrityError, models
1717
from django.utils import timezone
1818
from django.utils.translation import gettext_lazy as _
19-
from jsonfield import JSONField
2019
from openwisp_notifications.signals import notify
2120
from pytz import timezone as tz
2221
from pytz import utc
@@ -91,20 +90,16 @@ class AbstractMetric(TimeStampedEditableModel):
9190
)
9291
object_id = models.CharField(max_length=36, db_index=True, blank=True, null=True)
9392
content_object = GenericForeignKey("content_type", "object_id")
94-
main_tags = JSONField(
93+
main_tags = models.JSONField(
9594
_("main tags"),
9695
default=dict,
9796
blank=True,
98-
load_kwargs={"object_pairs_hook": OrderedDict},
99-
dump_kwargs={"indent": 4},
10097
db_index=True,
10198
)
102-
extra_tags = JSONField(
99+
extra_tags = models.JSONField(
103100
_("extra tags"),
104101
default=dict,
105102
blank=True,
106-
load_kwargs={"object_pairs_hook": OrderedDict},
107-
dump_kwargs={"indent": 4},
108103
)
109104
# NULL means the health has yet to be assessed
110105
is_healthy = models.BooleanField(default=None, null=True, blank=True, db_index=True)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Generated by Django 5.2.4 on 2025-07-08 16:30
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("monitoring", "0012_migrate_signal_metrics"),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name="metric",
15+
name="extra_tags",
16+
field=models.JSONField(blank=True, default=dict, verbose_name="extra tags"),
17+
),
18+
migrations.AlterField(
19+
model_name="metric",
20+
name="main_tags",
21+
field=models.JSONField(
22+
blank=True, db_index=True, default=dict, verbose_name="main tags"
23+
),
24+
),
25+
]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 5.2.4 on 2025-07-08 17:37
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("sample_check", "0003_add_check_inline_permissions"),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name="check",
15+
name="params",
16+
field=models.JSONField(
17+
blank=True,
18+
default=dict,
19+
help_text="parameters needed to perform the check",
20+
verbose_name="parameters",
21+
),
22+
),
23+
]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Generated by Django 5.2.4 on 2025-07-08 17:37
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("sample_monitoring", "0004_alter_metric_field_name"),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name="metric",
15+
name="extra_tags",
16+
field=models.JSONField(blank=True, default=dict, verbose_name="extra tags"),
17+
),
18+
migrations.AlterField(
19+
model_name="metric",
20+
name="main_tags",
21+
field=models.JSONField(
22+
blank=True, db_index=True, default=dict, verbose_name="main tags"
23+
),
24+
),
25+
]

0 commit comments

Comments
 (0)