summaryrefslogtreecommitdiff
path: root/django/db/backends
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2017-09-07 08:16:21 -0400
committerGitHub <noreply@github.com>2017-09-07 08:16:21 -0400
commit6e4c6281dbb7ee12bcdc22620894edb4e9cf623f (patch)
tree1c21218d4b6f00c499f18943d5190ebe7b5248c9 /django/db/backends
parent8b2515a450ef376b9205029090af0a79c8341bd7 (diff)
Reverted "Fixed #27818 -- Replaced try/except/pass with contextlib.suppress()."
This reverts commit 550cb3a365dee4edfdd1563224d5304de2a57fda because try/except performs better.
Diffstat (limited to 'django/db/backends')
-rw-r--r--django/db/backends/postgresql/client.py9
-rw-r--r--django/db/backends/sqlite3/operations.py10
2 files changed, 11 insertions, 8 deletions
diff --git a/django/db/backends/postgresql/client.py b/django/db/backends/postgresql/client.py
index 8d08b0d5cf..6d4cc9b692 100644
--- a/django/db/backends/postgresql/client.py
+++ b/django/db/backends/postgresql/client.py
@@ -1,7 +1,6 @@
import os
import signal
import subprocess
-from contextlib import suppress
from django.core.files.temp import NamedTemporaryFile
from django.db.backends.base.client import BaseDatabaseClient
@@ -41,9 +40,7 @@ class DatabaseClient(BaseDatabaseClient):
if passwd:
# Create temporary .pgpass file.
temp_pgpass = NamedTemporaryFile(mode='w+')
- # If the current locale can't encode the data, let the user
- # input the password manually.
- with suppress(UnicodeEncodeError):
+ try:
print(
_escape_pgpass(host) or '*',
str(port) or '*',
@@ -55,6 +52,10 @@ class DatabaseClient(BaseDatabaseClient):
flush=True,
)
os.environ['PGPASSFILE'] = temp_pgpass.name
+ except UnicodeEncodeError:
+ # If the current locale can't encode the data, let the
+ # user input the password manually.
+ pass
# Allow SIGINT to pass to psql to abort queries.
signal.signal(signal.SIGINT, signal.SIG_IGN)
subprocess.check_call(args)
diff --git a/django/db/backends/sqlite3/operations.py b/django/db/backends/sqlite3/operations.py
index 774d549461..408848c9ad 100644
--- a/django/db/backends/sqlite3/operations.py
+++ b/django/db/backends/sqlite3/operations.py
@@ -1,6 +1,5 @@
import datetime
import uuid
-from contextlib import suppress
from django.conf import settings
from django.core.exceptions import FieldError
@@ -36,10 +35,13 @@ class DatabaseOperations(BaseDatabaseOperations):
bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
if isinstance(expression, bad_aggregates):
for expr in expression.get_source_expressions():
- # Not every subexpression has an output_field which is fine
- # to ignore.
- with suppress(FieldError):
+ try:
output_field = expr.output_field
+ except FieldError:
+ # Not every subexpression has an output_field which is fine
+ # to ignore.
+ pass
+ else:
if isinstance(output_field, bad_fields):
raise NotImplementedError(
'You cannot use Sum, Avg, StdDev, and Variance '