mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-27 00:19:53 +03:00
replace try/except with context manager
This commit is contained in:
parent
573df163fc
commit
712317fb55
|
@ -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,12 +1498,10 @@ 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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user