mirror of
https://github.com/django/django.git
synced 2025-01-18 14:24:39 +00:00
Refs #33308 -- Used psycopg's errors instead of errorcodes.
This commit is contained in:
parent
e20fd899be
commit
3cafb783f3
@ -1,6 +1,6 @@
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from psycopg2 import errorcodes
|
from psycopg2 import errors
|
||||||
|
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.db.backends.base.creation import BaseDatabaseCreation
|
from django.db.backends.base.creation import BaseDatabaseCreation
|
||||||
@ -46,7 +46,8 @@ class DatabaseCreation(BaseDatabaseCreation):
|
|||||||
return
|
return
|
||||||
super()._execute_create_test_db(cursor, parameters, keepdb)
|
super()._execute_create_test_db(cursor, parameters, keepdb)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if getattr(e.__cause__, "pgcode", "") != errorcodes.DUPLICATE_DATABASE:
|
cause = e.__cause__
|
||||||
|
if cause and not isinstance(cause, errors.DuplicateDatabase):
|
||||||
# All errors except "database already exists" cancel tests.
|
# All errors except "database already exists" cancel tests.
|
||||||
self.log("Got an error creating the test database: %s" % e)
|
self.log("Got an error creating the test database: %s" % e)
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
@ -13,7 +13,7 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
from psycopg2 import errorcodes
|
from psycopg2 import errors
|
||||||
|
|
||||||
from django.db.backends.postgresql.creation import DatabaseCreation
|
from django.db.backends.postgresql.creation import DatabaseCreation
|
||||||
|
|
||||||
@ -73,13 +73,13 @@ class DatabaseCreationTests(SimpleTestCase):
|
|||||||
self.check_sql_table_creation_suffix(settings, None)
|
self.check_sql_table_creation_suffix(settings, None)
|
||||||
|
|
||||||
def _execute_raise_database_already_exists(self, cursor, parameters, keepdb=False):
|
def _execute_raise_database_already_exists(self, cursor, parameters, keepdb=False):
|
||||||
error = DatabaseError("database %s already exists" % parameters["dbname"])
|
error = errors.DuplicateDatabase(
|
||||||
error.pgcode = errorcodes.DUPLICATE_DATABASE
|
"database %s already exists" % parameters["dbname"]
|
||||||
|
)
|
||||||
raise DatabaseError() from error
|
raise DatabaseError() from error
|
||||||
|
|
||||||
def _execute_raise_permission_denied(self, cursor, parameters, keepdb=False):
|
def _execute_raise_permission_denied(self, cursor, parameters, keepdb=False):
|
||||||
error = DatabaseError("permission denied to create database")
|
error = errors.InsufficientPrivilege("permission denied to create database")
|
||||||
error.pgcode = errorcodes.INSUFFICIENT_PRIVILEGE
|
|
||||||
raise DatabaseError() from error
|
raise DatabaseError() from error
|
||||||
|
|
||||||
def patch_test_db_creation(self, execute_create_test_db):
|
def patch_test_db_creation(self, execute_create_test_db):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user