mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #33308 -- Added support for psycopg version 3.
Thanks Simon Charette, Tim Graham, and Adam Johnson for reviews. Co-authored-by: Florian Apolloner <florian@apolloner.eu> Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
This commit is contained in:
parent
d44ee518c4
commit
09ffc5c121
42 changed files with 673 additions and 223 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue