Skip to content
This repository was archived by the owner on Jan 28, 2022. It is now read-only.

Commit e408b3e

Browse files
author
Sergey Vilgelm
committed
Fix AttributeError for None or missing nested fields in __propagate_dump_mode__ function
1 parent 6c200fd commit e408b3e

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

marshmallow_objects/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ def __propagate_dump_mode__(self, value):
157157
self.__dump_mode__ = value
158158
for name, field in self.__schema__.fields.items():
159159
if isinstance(field, fields.Nested):
160-
getattr(self, name).__propagate_dump_mode__(value)
160+
nested = getattr(self, name, None)
161+
if nested is not None and nested != marshmallow.missing:
162+
nested.__propagate_dump_mode__(value)
161163

162164
@contextlib.contextmanager
163165
def __dump_mode_on__(self):

tests/test_models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ class MissingPerson(marshmallow.Model):
538538
class MissingCompany(marshmallow.Model):
539539
name = marshmallow.fields.String()
540540
owner = marshmallow.NestedModel(MissingPerson)
541+
hr = marshmallow.NestedModel(MissingPerson, allow_none=True)
541542

542543

543544
class TestMissingFields(unittest.TestCase):

0 commit comments

Comments
 (0)