-
-
Notifications
You must be signed in to change notification settings - Fork 227
Expand file tree
/
Copy path0044_convert_user_credentials_data.py
More file actions
45 lines (36 loc) · 1.34 KB
/
0044_convert_user_credentials_data.py
File metadata and controls
45 lines (36 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Generated by Django 5.2.9 on 2026-02-13 18:15
import json
import logging
from django.db import migrations
logger = logging.getLogger(__name__)
def convert_user_credentials_data(apps, schema_editor):
"""
Convert existing double-encoded JSON strings in user_credentials field
to proper JSON objects for Django's built-in JSONField.
"""
db_alias = schema_editor.connection.alias
RadiusBatch = apps.get_model("openwisp_radius", "RadiusBatch")
for batch in (
RadiusBatch.objects.using(db_alias)
.exclude(user_credentials__isnull=True)
.iterator()
):
if isinstance(batch.user_credentials, str):
try:
batch.user_credentials = json.loads(batch.user_credentials)
batch.save(using=db_alias, update_fields=["user_credentials"])
except Exception as e:
logger.exception(f"Encountered error while processing {batch}: {e}")
print(f"Encountered error while processing {batch}: {e}")
class Migration(migrations.Migration):
dependencies = [
(
"openwisp_radius",
"0043_alter_organizationradiussettings_sms_meta_data_and_more",
),
]
operations = [
migrations.RunPython(
convert_user_credentials_data, reverse_code=migrations.RunPython.noop
),
]