Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions tests/fields/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -3608,6 +3608,32 @@ def test_delete(self):
# deleted from the database
self.assertEqual(number, 2)

def test_only_populates_missing_listfield(self):
"""
Tests that getting a query result filtered by only() still populates
missing list fields with an empty list.
"""

class A(Document):
my_list = ListField(IntField())

app = A(my_list=[3]).save()
app.my_list = []
app.save()
# This creates a document without a my_list key in the a collection.


app2 = A.objects(id=app.id).get()
self.assertEqual(app2.my_list, [])

app3 = A.objects(id=app.id).only('my_list').get()
self.assertEqual(app3.my_list, [])

# This creates a document with a my_list key mapped to an empty list.
app4 = A(my_list=[]).save()
app5 = A.objects(id=app4.id).only('my_list').get()
self.assertEqual(app5.my_list, [])

def test_filtered_delete(self):
"""
Tests the delete method of a List of Embedded Documents
Expand Down