-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
Description
I noticed a problem where item_frequencies unexpectedly returns {None: 1}.
Here's my repro:
import mongoengine as me
import settings
me.connect('test', host=settings.MONGO_URL)
# Define a document type with a list field
class TestDocument(me.Document):
id = me.SequenceField(primary_key=True)
fruit = me.ListField(me.StringField())
# Insert one document that has a non-empty list
doc1 = TestDocument()
doc1.fruit = ['apple', 'orange']
doc1.save()
# Get the item_frequencies
item_frequencies = TestDocument.objects().item_frequencies('fruit')
print item_frequencies
# Change the document. Make it an empty list.
doc1.fruit = []
doc1.save()
# Get the item_frequencies again
item_frequencies = TestDocument.objects().item_frequencies('fruit')
print item_frequencies
Here's the output:
(venv)~/work> python -m data.item_frequencies_test
{u'orange': 1, u'apple': 1}
{None: 1}
Note that if the list starts out as empty then the problem doesn't repro. It only repros if the document first has a non-empty list and then has that list cleared out.