summaryrefslogtreecommitdiff
path: root/django/db/backends/postgresql/creation.py
diff options
context:
space:
mode:
authorFlorian Apolloner <florian@apolloner.eu>2022-12-01 08:35:14 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-12-01 09:17:33 +0100
commit3cafb783f3f711c7413ba2b8d7c8ff750bd4d6e1 (patch)
tree42bf4246a9538a712b75bada6ff4d14420dfd059 /django/db/backends/postgresql/creation.py
parente20fd899be87cf70ed5c4372c7b2ee634da1453a (diff)
Refs #33308 -- Used psycopg's errors instead of errorcodes.
Diffstat (limited to 'django/db/backends/postgresql/creation.py')
-rw-r--r--django/db/backends/postgresql/creation.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/django/db/backends/postgresql/creation.py b/django/db/backends/postgresql/creation.py
index 70c3eda566..690bf9639b 100644
--- a/django/db/backends/postgresql/creation.py
+++ b/django/db/backends/postgresql/creation.py
@@ -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)