summaryrefslogtreecommitdiff
path: root/django/db/backends/postgresql/creation.py
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2017-04-25 06:01:25 +0200
committerGitHub <noreply@github.com>2017-04-25 06:01:25 +0200
commite776dd2db677d58dcb50aea20d3bb191537df25b (patch)
tree9f7df94bd346a13f1fd2a61421600a1a7fc70013 /django/db/backends/postgresql/creation.py
parent5e8625ba643db118a44cb32e9e48bf431ef4da53 (diff)
downloaddjango-e776dd2db677d58dcb50aea20d3bb191537df25b.tar.gz
Fixed #28116 -- Used error code filtering in PostgreSQL test database creation.
Thanks Claude Paroz and Tim Graham for reviews.
Diffstat (limited to 'django/db/backends/postgresql/creation.py')
-rw-r--r--django/db/backends/postgresql/creation.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/django/db/backends/postgresql/creation.py b/django/db/backends/postgresql/creation.py
index 27963e9462..a233758eea 100644
--- a/django/db/backends/postgresql/creation.py
+++ b/django/db/backends/postgresql/creation.py
@@ -1,5 +1,7 @@
import sys
+from psycopg2 import errorcodes
+
from django.db.backends.base.creation import BaseDatabaseCreation
@@ -32,9 +34,8 @@ class DatabaseCreation(BaseDatabaseCreation):
try:
super()._execute_create_test_db(cursor, parameters, keepdb)
except Exception as e:
- exc_msg = 'database %s already exists' % parameters['dbname']
- if exc_msg not in str(e):
- # All errors except "database already exists" cancel tests
+ if getattr(e.__cause__, 'pgcode', '') != errorcodes.DUPLICATE_DATABASE:
+ # All errors except "database already exists" cancel tests.
sys.stderr.write('Got an error creating the test database: %s\n' % e)
sys.exit(2)
elif not keepdb: