replace try/except with context manager

This commit is contained in:
ahzam 2022-09-28 01:26:35 +05:00
parent 573df163fc
commit 712317fb55

View File

@ -10,6 +10,8 @@ python primitives.
2. The process of marshalling between python primitives and request and 2. The process of marshalling between python primitives and request and
response content is handled by parsers and renderers. response content is handled by parsers and renderers.
""" """
import contextlib
import copy import copy
import inspect import inspect
import traceback import traceback
@ -1496,13 +1498,11 @@ class ModelSerializer(Serializer):
# they can't be nested attribute lookups. # they can't be nested attribute lookups.
continue continue
try: with contextlib.suppress(FieldDoesNotExist):
field = model._meta.get_field(source) field = model._meta.get_field(source)
if isinstance(field, DjangoModelField): if isinstance(field, DjangoModelField):
model_fields[source] = field model_fields[source] = field
except FieldDoesNotExist:
pass
return model_fields return model_fields
# Determine the validators to apply... # Determine the validators to apply...