From d24aab4d423fa2721461136c07f0d705799e8fe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Dlouh=C3=BD?= Date: Wed, 21 Sep 2022 17:56:12 +0200 Subject: [PATCH] more Django 4.1 fixes --- categories/management/commands/add_category_fields.py | 2 +- categories/management/commands/drop_category_field.py | 2 +- categories/migration.py | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/categories/management/commands/add_category_fields.py b/categories/management/commands/add_category_fields.py index de315a4..ebba247 100644 --- a/categories/management/commands/add_category_fields.py +++ b/categories/management/commands/add_category_fields.py @@ -10,7 +10,7 @@ class Command(BaseCommand): help = "Alter the tables for all registered models, or just specified models" args = "[appname ...]" can_import_settings = True - requires_system_checks = False + requires_system_checks = [] def add_arguments(self, parser): """Add app_names argument to the command.""" diff --git a/categories/management/commands/drop_category_field.py b/categories/management/commands/drop_category_field.py index ca48b39..77837ac 100644 --- a/categories/management/commands/drop_category_field.py +++ b/categories/management/commands/drop_category_field.py @@ -10,7 +10,7 @@ class Command(BaseCommand): help = "Drop the given field from the given model's table" args = "appname modelname fieldname" can_import_settings = True - requires_system_checks = False + requires_system_checks = [] def add_arguments(self, parser): """Add app_name, model_name, and field_name arguments to the command.""" diff --git a/categories/migration.py b/categories/migration.py index fc227ee..1561b31 100644 --- a/categories/migration.py +++ b/categories/migration.py @@ -1,7 +1,7 @@ """Adds and removes category relations on the database.""" from django.apps import apps from django.db import DatabaseError, connection, transaction -from django.db.utils import ProgrammingError +from django.db.utils import OperationalError, ProgrammingError def table_exists(table_name): @@ -71,7 +71,9 @@ def migrate_app(sender, *args, **kwargs): schema_editor.add_field(model, registry._field_registry[fld]) if sid: transaction.savepoint_commit(sid) - except ProgrammingError: + # Django 4.1 with sqlite3 has for some reason started throwing OperationalError + # instead of ProgrammingError, so we need to catch both. + except (ProgrammingError, OperationalError): if sid: transaction.savepoint_rollback(sid) continue