Skip to content

Commit

Permalink
fix(migrations): make app prefix migration language independent
Browse files Browse the repository at this point in the history
Currently, the migration to add prefixes failed on initial migrations if
the database server is not in English. This commit removes the
dependency on the error message and instead uses the underlying psycopg
exception which is more specific.
  • Loading branch information
anehx committed Aug 31, 2023
1 parent f4fe28c commit 2f3a5d3
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.core.management.base import BaseCommand
from django.db import connection
from django.db.utils import ProgrammingError
from psycopg2.errors import UndefinedTable


class Command(BaseCommand):
Expand Down Expand Up @@ -35,8 +36,10 @@ def _migration_needed(self):
try:
cursor.execute(query, params=None)
except ProgrammingError as e: # pragma: no cover
# happens only on initial migration for new project
if e.args[0].startswith('relation "django_migrations" does not exist'):
# Happens only on initial migration for new project.
# `e.__cause__` contains the underlying psycopg2 exception
# which is more specific than the django wrapper exception
if isinstance(e.__cause__, UndefinedTable):
return False
raise
if cursor.fetchone():
Expand Down

0 comments on commit 2f3a5d3

Please sign in to comment.