summaryrefslogtreecommitdiff
path: root/django/db/backends/postgresql
diff options
context:
space:
mode:
Diffstat (limited to 'django/db/backends/postgresql')
-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: