Skip to content

Commit

Permalink
fix-MongoEngine#620: saving document doesn't create new fields in exi…
Browse files Browse the repository at this point in the history
…sting collection
  • Loading branch information
DavidBord committed Aug 5, 2014
1 parent e008919 commit 1e6a316
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mongoengine/base/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,8 @@ def _from_son(cls, son, _auto_dereference=True, only_fields=[]):
default = default()
if isinstance(default, BaseDocument):
changed_fields.append(field_name)
elif not only_fields or field_name in only_fields:
changed_fields.append(field_name)

if errors_dict:
errors = "\n".join(["%s - %s" % (k, v)
Expand Down
10 changes: 10 additions & 0 deletions tests/document/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2633,5 +2633,15 @@ class Person(Document):
p3 = Person.objects().only('created_on')[0]
self.assertEquals(orig_created_on, p3.created_on)

class Person(Document):
created_on = DateTimeField(default=lambda: datetime.utcnow())
name = StringField()
height = IntField(default=189)

p4 = Person.objects()[0]
p4.save()
self.assertEquals(p4.height, 189)
self.assertEquals(Person.objects(height=189).count(), 1)

if __name__ == '__main__':
unittest.main()

0 comments on commit 1e6a316

Please sign in to comment.