mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +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
|
||||
|
||||
from psycopg2 import errorcodes
|
||||
from psycopg2 import errors
|
||||
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.db.backends.base.creation import BaseDatabaseCreation
|
||||
@ -46,7 +46,8 @@ class DatabaseCreation(BaseDatabaseCreation):
|
||||
return
|
||||
super()._execute_create_test_db(cursor, parameters, keepdb)
|
||||
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.
|
||||
self.log("Got an error creating the test database: %s" % e)
|
||||
sys.exit(2)
|
||||
|
@ -13,7 +13,7 @@ try:
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
from psycopg2 import errorcodes
|
||||
from psycopg2 import errors
|
||||
|
||||
from django.db.backends.postgresql.creation import DatabaseCreation
|
||||
|
||||
@ -73,13 +73,13 @@ class DatabaseCreationTests(SimpleTestCase):
|
||||
self.check_sql_table_creation_suffix(settings, None)
|
||||
|
||||
def _execute_raise_database_already_exists(self, cursor, parameters, keepdb=False):
|
||||
error = DatabaseError("database %s already exists" % parameters["dbname"])
|
||||
error.pgcode = errorcodes.DUPLICATE_DATABASE
|
||||
error = errors.DuplicateDatabase(
|
||||
"database %s already exists" % parameters["dbname"]
|
||||
)
|
||||
raise DatabaseError() from error
|
||||
|
||||
def _execute_raise_permission_denied(self, cursor, parameters, keepdb=False):
|
||||
error = DatabaseError("permission denied to create database")
|
||||
error.pgcode = errorcodes.INSUFFICIENT_PRIVILEGE
|
||||
error = errors.InsufficientPrivilege("permission denied to create database")
|
||||
raise DatabaseError() from error
|
||||
|
||||
def patch_test_db_creation(self, execute_create_test_db):
|
||||
|
Loading…
Reference in New Issue
Block a user