fix-#771: OperationError: Shard Keys are immutable. Tried to update id even though the document is not yet saved

This commit is contained in:
David Bordeynik
2014-11-09 19:23:49 +02:00
parent c4f7db6c04
commit 0452eec11d
3 changed files with 16 additions and 4 deletions

View File

@@ -2719,5 +2719,16 @@ class InstanceTest(unittest.TestCase):
self.assertEquals(p4.height, 189)
self.assertEquals(Person.objects(height=189).count(), 1)
def test_from_son(self):
# 771
class MyPerson(self.Person):
meta = dict(shard_key=["id"])
p = MyPerson.from_json('{"name": "name", "age": 27}', created=True)
self.assertEquals(p.id, None)
p.id = "12345" # in case it is not working: "OperationError: Shard Keys are immutable..." will be raised here
p = MyPerson._from_son({"name": "name", "age": 27}, created=True)
self.assertEquals(p.id, None)
p.id = "12345" # in case it is not working: "OperationError: Shard Keys are immutable..." will be raised here
if __name__ == '__main__':
unittest.main()