summaryrefslogtreecommitdiff
path: root/django/db/backends/postgresql/base.py
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2020-02-03 19:07:00 -0800
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-02-06 15:35:23 +0100
commit3259983f569151232d8e3b0c3d0de3a858c2b265 (patch)
tree4f1f19368fbb9d73ea5245d8fabe5e3097f51926 /django/db/backends/postgresql/base.py
parentf48f671223a20b161ca819cf7d6298e43b8ba5fe (diff)
Fixed #31233 -- Closed database connections and cursors after use.
Diffstat (limited to 'django/db/backends/postgresql/base.py')
-rw-r--r--django/db/backends/postgresql/base.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py
index 0f45ca93e1..192316d7fb 100644
--- a/django/db/backends/postgresql/base.py
+++ b/django/db/backends/postgresql/base.py
@@ -277,13 +277,15 @@ class DatabaseWrapper(BaseDatabaseWrapper):
Check constraints by setting them to immediate. Return them to deferred
afterward.
"""
- self.cursor().execute('SET CONSTRAINTS ALL IMMEDIATE')
- self.cursor().execute('SET CONSTRAINTS ALL DEFERRED')
+ with self.cursor() as cursor:
+ cursor.execute('SET CONSTRAINTS ALL IMMEDIATE')
+ cursor.execute('SET CONSTRAINTS ALL DEFERRED')
def is_usable(self):
try:
# Use a psycopg cursor directly, bypassing Django's utilities.
- self.connection.cursor().execute("SELECT 1")
+ with self.connection.cursor() as cursor:
+ cursor.execute('SELECT 1')
except Database.Error:
return False
else: