summaryrefslogtreecommitdiff
path: root/tests/db_utils
diff options
context:
space:
mode:
Diffstat (limited to 'tests/db_utils')
-rw-r--r--tests/db_utils/tests.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/tests/db_utils/tests.py b/tests/db_utils/tests.py
index 9c0ec905cc..a2d9cc7b5e 100644
--- a/tests/db_utils/tests.py
+++ b/tests/db_utils/tests.py
@@ -62,14 +62,20 @@ class ConnectionHandlerTests(SimpleTestCase):
class DatabaseErrorWrapperTests(TestCase):
@unittest.skipUnless(connection.vendor == "postgresql", "PostgreSQL test")
def test_reraising_backend_specific_database_exception(self):
+ from django.db.backends.postgresql.psycopg_any import is_psycopg3
+
with connection.cursor() as cursor:
msg = 'table "X" does not exist'
with self.assertRaisesMessage(ProgrammingError, msg) as cm:
cursor.execute('DROP TABLE "X"')
self.assertNotEqual(type(cm.exception), type(cm.exception.__cause__))
self.assertIsNotNone(cm.exception.__cause__)
- self.assertIsNotNone(cm.exception.__cause__.pgcode)
- self.assertIsNotNone(cm.exception.__cause__.pgerror)
+ if is_psycopg3:
+ self.assertIsNotNone(cm.exception.__cause__.diag.sqlstate)
+ self.assertIsNotNone(cm.exception.__cause__.diag.message_primary)
+ else:
+ self.assertIsNotNone(cm.exception.__cause__.pgcode)
+ self.assertIsNotNone(cm.exception.__cause__.pgerror)
class LoadBackendTests(SimpleTestCase):