Fixed #33160 -- Avoided suppressing query errors in _nodb_cursor() on PostgreSQL.
This commit is contained in:
parent
492ed60f23
commit
98c8bf1cee
|
@ -304,10 +304,13 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def _nodb_cursor(self):
|
def _nodb_cursor(self):
|
||||||
|
cursor = None
|
||||||
try:
|
try:
|
||||||
with super()._nodb_cursor() as cursor:
|
with super()._nodb_cursor() as cursor:
|
||||||
yield cursor
|
yield cursor
|
||||||
except (Database.DatabaseError, WrappedDatabaseError):
|
except (Database.DatabaseError, WrappedDatabaseError):
|
||||||
|
if cursor is not None:
|
||||||
|
raise
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"Normally Django will use a connection to the 'postgres' database "
|
"Normally Django will use a connection to the 'postgres' database "
|
||||||
"to avoid running initialization queries against the production "
|
"to avoid running initialization queries against the production "
|
||||||
|
|
|
@ -103,6 +103,11 @@ class Tests(TestCase):
|
||||||
with connection._nodb_cursor():
|
with connection._nodb_cursor():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def test_nodb_cursor_reraise_exceptions(self):
|
||||||
|
with self.assertRaisesMessage(DatabaseError, 'exception'):
|
||||||
|
with connection._nodb_cursor():
|
||||||
|
raise DatabaseError('exception')
|
||||||
|
|
||||||
def test_database_name_too_long(self):
|
def test_database_name_too_long(self):
|
||||||
from django.db.backends.postgresql.base import DatabaseWrapper
|
from django.db.backends.postgresql.base import DatabaseWrapper
|
||||||
settings = connection.settings_dict.copy()
|
settings = connection.settings_dict.copy()
|
||||||
|
|
Loading…
Reference in New Issue