Merge pull request #936 from MRigal/fix/712-avoid-crash-looping-on-corrupted-obj-id

changed ObjectIdField to_python() method to avoid crash, issue 712
This commit is contained in:
Matthieu Rigal
2015-06-14 23:31:22 +02:00
2 changed files with 12 additions and 2 deletions

View File

@@ -4693,6 +4693,13 @@ class QuerySetTest(unittest.TestCase):
self.assertEquals(Animal.objects(folded_ears=True).count(), 1)
self.assertEquals(Animal.objects(whiskers_length=5.1).count(), 1)
def test_loop_via_invalid_id_does_not_crash(self):
class Person(Document):
name = StringField()
Person.objects.delete()
Person._get_collection().update({"name": "a"}, {"$set": {"_id": ""}}, upsert=True)
for p in Person.objects():
self.assertEqual(p.name, 'a')
if __name__ == '__main__':
unittest.main()