Skip to content

Commit

Permalink
more Django 4.1 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrDlouhy committed Sep 21, 2022
1 parent b66777e commit d24aab4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion categories/management/commands/add_category_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
2 changes: 1 addition & 1 deletion categories/management/commands/drop_category_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
6 changes: 4 additions & 2 deletions categories/migration.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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

0 comments on commit d24aab4

Please sign in to comment.