Closed tiltowait closed 2 years ago
This appears to be the same (or similar) issue to https://github.com/Scille/umongo/issues/371
For fields with default values, try to use the following
dictionary = fields.DictField(default=dict)
Instead of
dictionary = fields.DictField(default={})
default=dict
fixes the top-level dictionary test. It does not, however, fix the embedded document tests. To be clear, the following is still initialized with incorrect values on subsequent document creation:
@instance.register
class EmbeddedWithDict(EmbeddedDocument):
embedded_dict = fields.DictField(default=dict)
embedded_str = fields.StrField(default=str)
How about changing this:
embedded = fields.EmbeddedField(EmbeddedWithDict, default=EmbeddedWithDict())
to
embedded = fields.EmbeddedField(EmbeddedWithDict, default=EmbeddedWithDict)
That works! (And as soon as you posted it, it was a total facepalm moment.)
When creating a new document, fields in embedded documents, as well as top-level
DictField
s, aren't receiving their default values. Instead, they receive the values of whatever the last-committed document had. The complete program below demonstrates the issue.