When using autogenerated document ids in a sharded collection, do set that id back into the Document

This commit is contained in:
Ronald van Rij 2014-05-05 16:39:55 +02:00
parent f099dc6a37
commit babbc8bcd6
2 changed files with 5 additions and 1 deletions

View File

@ -293,7 +293,7 @@ class Document(BaseDocument):
raise NotUniqueError(message % unicode(err))
raise OperationError(message % unicode(err))
id_field = self._meta['id_field']
if id_field not in self._meta.get('shard_key', []):
if created or id_field not in self._meta.get('shard_key', []):
self[id_field] = self._fields[id_field].to_python(object_id)
self._clear_changed_fields()

View File

@ -2281,6 +2281,8 @@ class InstanceTest(unittest.TestCase):
log.machine = "Localhost"
log.save()
self.assertIsNotNone(log.id)
log.log = "Saving"
log.save()
@ -2304,6 +2306,8 @@ class InstanceTest(unittest.TestCase):
log.machine = "Localhost"
log.save()
self.assertIsNotNone(log.id)
log.log = "Saving"
log.save()