mirror of
https://github.com/django/django.git
synced 2025-09-26 12:09:19 +00:00
Fixed #27818 -- Replaced try/except/pass with contextlib.suppress().
This commit is contained in:
parent
43a4835edf
commit
550cb3a365
67 changed files with 223 additions and 368 deletions
|
@ -6,6 +6,7 @@ import copy
|
|||
import sys
|
||||
import warnings
|
||||
from collections import OrderedDict, deque
|
||||
from contextlib import suppress
|
||||
|
||||
from django.conf import settings
|
||||
from django.core import exceptions
|
||||
|
@ -488,10 +489,8 @@ class QuerySet:
|
|||
return obj, True
|
||||
except IntegrityError:
|
||||
exc_info = sys.exc_info()
|
||||
try:
|
||||
with suppress(self.model.DoesNotExist):
|
||||
return self.get(**lookup), False
|
||||
except self.model.DoesNotExist:
|
||||
pass
|
||||
raise exc_info[0](exc_info[1]).with_traceback(exc_info[2])
|
||||
|
||||
def _extract_model_params(self, defaults, **kwargs):
|
||||
|
@ -1256,12 +1255,10 @@ class RawQuerySet:
|
|||
columns = self.query.get_columns()
|
||||
# Adjust any column names which don't match field names
|
||||
for (query_name, model_name) in self.translations.items():
|
||||
try:
|
||||
# Ignore translations for nonexistent column names
|
||||
with suppress(ValueError):
|
||||
index = columns.index(query_name)
|
||||
columns[index] = model_name
|
||||
except ValueError:
|
||||
# Ignore translations for nonexistent column names
|
||||
pass
|
||||
return columns
|
||||
|
||||
@cached_property
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue