From 09ffc5c1212d4ced58b708cbbf3dfbfb77b782ca Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Thu, 1 Dec 2022 20:23:43 +0100 Subject: Fixed #33308 -- Added support for psycopg version 3. Thanks Simon Charette, Tim Graham, and Adam Johnson for reviews. Co-authored-by: Florian Apolloner Co-authored-by: Mariusz Felisiak --- tests/db_utils/tests.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'tests/db_utils') 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): -- cgit v1.3