Fix AttributeError when obj is None

This commit is contained in:
Diogo
2021-10-19 16:46:18 +01:00
parent 50df1bb2f6
commit 441d6edd58

View File

@@ -134,7 +134,11 @@ class Model(Resource):
continue
if isinstance(input_, inputs.File):
cls.enctype = "multipart/form-data"
if isinstance(input_, inputs.ForeignKey) and name in obj._meta.fk_fields:
if (
isinstance(input_, inputs.ForeignKey)
and (obj is not None)
and name in obj._meta.fk_fields
):
await obj.fetch_related(name)
# Value must be the string representation of the fk obj
value = str(getattr(obj, name, None))