hmarr/mongoengine — Issue #355: ListField(ReferenceField) appends ignored if empty array passed into constructor
Author: joeshaw
Created: 2011-11-11 21:22:39+00:00
State: open

If you pass an empty list into the constructor of a Document with a `ListField(ReferenceField(...))`, it is never successfully appended.

class Foo(Document):
bars = ListField(ReferenceField("Bar"))

class Bar(Document):
text = StringField()

bar = Bar(text="hi")
bar.save()

foo = Foo(bars=[])
foo.bars.append(bar)

print foo.bars # => []

foo.bars.append(bar)

print foo.bars # => [] -- doesn't matter how many times you try

foo = Foo()
foo.bars.append(bar)

print foo.bars # => []