From 9e904a1d9a500e4fc2091da0c24a27c2cf1b9e1a Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Wed, 23 Nov 2022 15:27:27 +0100 Subject: [PATCH 2/2] django.contrib.postgres's JSONField is deprecated (#71619) --- .../apps/journal/migrations/0001_initial.py | 8 ++++++-- src/authentic2/apps/journal/models.py | 7 ++++++- .../custom_user/migrations/0020_deleteduser.py | 10 ++++++---- .../migrations/0029_profile_profiletype.py | 10 ++++++---- src/authentic2/custom_user/models.py | 6 +++++- src/authentic2/migrations/0026_token.py | 8 ++++++-- src/authentic2/models.py | 8 ++++++-- .../migrations/0001_initial.py | 8 ++++++-- src/authentic2_auth_oidc/models.py | 6 +++++- .../migrations/0001_initial.py | 14 +++++++++----- src/authentic2_auth_saml/models.py | 6 +++++- 11 files changed, 66 insertions(+), 25 deletions(-) diff --git a/src/authentic2/apps/journal/migrations/0001_initial.py b/src/authentic2/apps/journal/migrations/0001_initial.py index 814fa38b..e20f5db9 100644 --- a/src/authentic2/apps/journal/migrations/0001_initial.py +++ b/src/authentic2/apps/journal/migrations/0001_initial.py @@ -1,12 +1,16 @@ # Generated by Django 2.2.15 on 2020-08-23 16:56 import django.contrib.postgres.fields -import django.contrib.postgres.fields.jsonb import django.db.models.deletion from django.conf import settings from django.db import migrations, models from django.utils import timezone +try: + from django.db.models import JSONField +except ImportError: + from django.contrib.postgres.fields.jsonb import JSONField + class Migration(migrations.Migration): @@ -65,7 +69,7 @@ class Migration(migrations.Migration): verbose_name='reference ct ids', ), ), - ('data', django.contrib.postgres.fields.jsonb.JSONField(null=True, verbose_name='data')), + ('data', JSONField(null=True, verbose_name='data')), ( 'session', models.ForeignKey( diff --git a/src/authentic2/apps/journal/models.py b/src/authentic2/apps/journal/models.py index 1ab7fd93..cf264863 100644 --- a/src/authentic2/apps/journal/models.py +++ b/src/authentic2/apps/journal/models.py @@ -26,11 +26,16 @@ import django from django.conf import settings from django.contrib.auth import get_user_model from django.contrib.contenttypes.models import ContentType -from django.contrib.postgres.fields import ArrayField, JSONField +from django.contrib.postgres.fields import ArrayField from django.contrib.postgres.fields.jsonb import KeyTextTransform from django.core.exceptions import ObjectDoesNotExist from django.db import models from django.db.models import Count, F, Q, QuerySet, Value + +try: + from django.db.models import JSONField +except ImportError: + from django.contrib.postgres.fields import JSONField from django.db.models.functions import Trunc from django.utils.timezone import now, utc from django.utils.translation import gettext_lazy as _ diff --git a/src/authentic2/custom_user/migrations/0020_deleteduser.py b/src/authentic2/custom_user/migrations/0020_deleteduser.py index 68dd9e1c..c1352e7b 100644 --- a/src/authentic2/custom_user/migrations/0020_deleteduser.py +++ b/src/authentic2/custom_user/migrations/0020_deleteduser.py @@ -1,8 +1,12 @@ # Generated by Django 2.2.12 on 2020-05-05 14:16 -import django.contrib.postgres.fields.jsonb from django.db import migrations, models +try: + from django.db.models import JSONField +except ImportError: + from django.contrib.postgres.fields.jsonb import JSONField + class Migration(migrations.Migration): @@ -30,9 +34,7 @@ class Migration(migrations.Migration): ), ( 'old_data', - django.contrib.postgres.fields.jsonb.JSONField( - blank=True, null=True, verbose_name='Old data' - ), + JSONField(blank=True, null=True, verbose_name='Old data'), ), ], options={ diff --git a/src/authentic2/custom_user/migrations/0029_profile_profiletype.py b/src/authentic2/custom_user/migrations/0029_profile_profiletype.py index ab5341d0..02cb5666 100644 --- a/src/authentic2/custom_user/migrations/0029_profile_profiletype.py +++ b/src/authentic2/custom_user/migrations/0029_profile_profiletype.py @@ -2,11 +2,15 @@ import uuid -import django.contrib.postgres.fields.jsonb import django.db.models.deletion from django.conf import settings from django.db import migrations, models +try: + from django.db.models import JSONField +except ImportError: + from django.contrib.postgres.fields.jsonb import JSONField + class Migration(migrations.Migration): @@ -48,9 +52,7 @@ class Migration(migrations.Migration): ), ( 'data', - django.contrib.postgres.fields.jsonb.JSONField( - blank=True, null=True, verbose_name='data' - ), + JSONField(blank=True, null=True, verbose_name='data'), ), ( 'profile_type', diff --git a/src/authentic2/custom_user/models.py b/src/authentic2/custom_user/models.py index b15ef1b2..66cbf09d 100644 --- a/src/authentic2/custom_user/models.py +++ b/src/authentic2/custom_user/models.py @@ -27,11 +27,15 @@ from django.contrib.auth.models import AbstractBaseUser, Group from django.contrib.auth.models import Permission as AuthPermission from django.contrib.auth.models import _user_has_module_perms, _user_has_perm from django.contrib.contenttypes.fields import GenericRelation -from django.contrib.postgres.fields import JSONField from django.core.exceptions import MultipleObjectsReturned, ValidationError from django.core.mail import send_mail from django.db import models, transaction from django.db.models import Q + +try: + from django.db.models import JSONField +except ImportError: + from django.contrib.postgres.fields import JSONField from django.urls import reverse from django.utils import timezone from django.utils.translation import gettext_lazy as _ diff --git a/src/authentic2/migrations/0026_token.py b/src/authentic2/migrations/0026_token.py index 0be9eea6..4283d873 100644 --- a/src/authentic2/migrations/0026_token.py +++ b/src/authentic2/migrations/0026_token.py @@ -2,9 +2,13 @@ import uuid -import django.contrib.postgres.fields.jsonb from django.db import migrations, models +try: + from django.db.models import JSONField +except ImportError: + from django.contrib.postgres.fields.jsonb import JSONField + class Migration(migrations.Migration): @@ -29,7 +33,7 @@ class Migration(migrations.Migration): ('kind', models.CharField(max_length=32, verbose_name='Kind')), ( 'content', - django.contrib.postgres.fields.jsonb.JSONField(blank=True, verbose_name='Content'), + JSONField(blank=True, verbose_name='Content'), ), ('created', models.DateTimeField(verbose_name='Creation date', auto_now_add=True)), ('expires', models.DateTimeField(verbose_name='Expires')), diff --git a/src/authentic2/models.py b/src/authentic2/models.py index a25a71bc..b9e3d9a8 100644 --- a/src/authentic2/models.py +++ b/src/authentic2/models.py @@ -27,12 +27,16 @@ from django.conf import settings from django.contrib import auth from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.models import ContentType -from django.contrib.postgres.fields import jsonb from django.contrib.postgres.indexes import GinIndex from django.contrib.postgres.search import SearchVectorField from django.core.exceptions import PermissionDenied, ValidationError from django.db import DatabaseError, models, transaction from django.db.models.query import Q + +try: + from django.db.models import JSONField +except ImportError: + from django.contrib.postgres.fields import JSONField from django.urls import reverse from django.utils import timezone from django.utils.http import urlquote @@ -538,7 +542,7 @@ class Token(models.Model): verbose_name=_('Identifier'), primary_key=True, default=uuid.uuid4, editable=False ) kind = models.CharField(verbose_name=_('Kind'), max_length=32) - content = jsonb.JSONField(verbose_name=_('Content'), blank=True) + content = JSONField(verbose_name=_('Content'), blank=True) created = models.DateTimeField(verbose_name=_('Creation date'), auto_now_add=True) expires = models.DateTimeField(verbose_name=_('Expires')) diff --git a/src/authentic2_auth_oidc/migrations/0001_initial.py b/src/authentic2_auth_oidc/migrations/0001_initial.py index 57b6d3a0..5a2ec322 100644 --- a/src/authentic2_auth_oidc/migrations/0001_initial.py +++ b/src/authentic2_auth_oidc/migrations/0001_initial.py @@ -1,7 +1,11 @@ -import django.contrib.postgres.fields.jsonb from django.conf import settings from django.db import migrations, models +try: + from django.db.models import JSONField +except ImportError: + from django.contrib.postgres.fields.jsonb import JSONField + import authentic2_auth_oidc.models @@ -88,7 +92,7 @@ class Migration(migrations.Migration): ('scopes', models.CharField(max_length=128, verbose_name='scopes', blank=True)), ( 'jwkset_json', - django.contrib.postgres.fields.jsonb.JSONField( + JSONField( blank=True, null=True, verbose_name='JSON WebKey set', diff --git a/src/authentic2_auth_oidc/models.py b/src/authentic2_auth_oidc/models.py index 06ac0521..c2ecfb7e 100644 --- a/src/authentic2_auth_oidc/models.py +++ b/src/authentic2_auth_oidc/models.py @@ -17,9 +17,13 @@ import json from django.conf import settings -from django.contrib.postgres.fields import JSONField from django.core.exceptions import ValidationError from django.db import models + +try: + from django.db.models import JSONField +except ImportError: + from django.contrib.postgres.fields import JSONField from django.shortcuts import render from django.utils.translation import gettext_lazy as _ from django.utils.translation import pgettext_lazy diff --git a/src/authentic2_auth_saml/migrations/0001_initial.py b/src/authentic2_auth_saml/migrations/0001_initial.py index 66ddeed6..abec64d9 100644 --- a/src/authentic2_auth_saml/migrations/0001_initial.py +++ b/src/authentic2_auth_saml/migrations/0001_initial.py @@ -1,9 +1,13 @@ # Generated by Django 2.2.26 on 2022-06-15 15:00 -import django.contrib.postgres.fields.jsonb import django.db.models.deletion from django.db import migrations, models +try: + from django.db.models import JSONField +except ImportError: + from django.contrib.postgres.fields.jsonb import JSONField + import authentic2_auth_saml.models from authentic2_auth_saml.models import NAME_ID_FORMAT_CHOICES @@ -203,7 +207,7 @@ class Migration(migrations.Migration): ), ( 'lookup_by_attributes', - django.contrib.postgres.fields.jsonb.JSONField( + JSONField( blank=True, default=list, help_text=( @@ -218,7 +222,7 @@ class Migration(migrations.Migration): ), ( 'a2_attribute_mapping', - django.contrib.postgres.fields.jsonb.JSONField( + JSONField( blank=True, default=list, help_text=( @@ -230,7 +234,7 @@ class Migration(migrations.Migration): ), ( 'attribute_mapping', - django.contrib.postgres.fields.jsonb.JSONField( + JSONField( blank=True, default=dict, help_text=( @@ -242,7 +246,7 @@ class Migration(migrations.Migration): ), ( 'superuser_mapping', - django.contrib.postgres.fields.jsonb.JSONField( + JSONField( blank=True, default=dict, editable=False, diff --git a/src/authentic2_auth_saml/models.py b/src/authentic2_auth_saml/models.py index ce811387..9dce3a1c 100644 --- a/src/authentic2_auth_saml/models.py +++ b/src/authentic2_auth_saml/models.py @@ -18,9 +18,13 @@ import xml.etree.ElementTree as ET import lasso from django.conf import settings -from django.contrib.postgres.fields import JSONField from django.core.exceptions import ValidationError from django.db import models + +try: + from django.db.models import JSONField +except ImportError: + from django.contrib.postgres.fields import JSONField from django.urls import reverse from django.utils.safestring import mark_safe from django.utils.translation import gettext_lazy as _ -- 2.37.2