Skip to content

Commit

Permalink
Fixed #33160 -- Avoided suppressing query errors in _nodb_cursor() on…
Browse files Browse the repository at this point in the history
… PostgreSQL.
  • Loading branch information
blueyed committed Oct 1, 2021
1 parent 492ed60 commit 98c8bf1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions django/db/backends/postgresql/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,13 @@ def is_usable(self):

@contextmanager
def _nodb_cursor(self):
cursor = None
try:
with super()._nodb_cursor() as cursor:
yield cursor
except (Database.DatabaseError, WrappedDatabaseError):
if cursor is not None:
raise
warnings.warn(
"Normally Django will use a connection to the 'postgres' database "
"to avoid running initialization queries against the production "
Expand Down
5 changes: 5 additions & 0 deletions tests/backends/postgresql/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ def mocked_all(self):
with connection._nodb_cursor():
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):
from django.db.backends.postgresql.base import DatabaseWrapper
settings = connection.settings_dict.copy()
Expand Down

0 comments on commit 98c8bf1

Please sign in to comment.