sbook/flask-mongoengine — Issue #12: ListField(ReferenceField) fails to append (but only the first time)
Author: maxcountryman
Created: 2011-11-04 16:13:36+00:00
State: open

I am having this bizarre issue, which may be related to MongoEngine itself, rather than the Flask wrapper but basically what you do to reproduce is create a couple of models similar to:

Comment(db.Document):
body = db.StringField()

Post(db.Document):
comments = db.ListField(db.ReferenceField(Comment))

Now if I create a Post object, save it, and then create a comment object, save it, and finally append the comment reference to the post reference, such as: post.comments.append(comment); post.save. This will fail on the first attempt. The list of references in the post object will return []. However on the second attempt (and apparently all subsequent attempts) the comment reference is successfully appended and behaves as expected.

Any thoughts?