heynemann / motorengine

Motorengine is a port of MongoEngine for Tornado.
http://motorengine.readthedocs.org
204 stars 67 forks source link

Overwritten values with DynamicFields if two versions of the same document-definition exist #104

Closed christ0pher closed 8 years ago

christ0pher commented 8 years ago

Hi,

thanks for the lib and all the work!

There is a rare case when two versions of the same document exist and DynamicFields are created and then overwrite values. This happens when: You have two services. The newer services adds new fields to the database-definition. When the older version reads the database there might be some unknown fields. For those fields it creates DynamicFields and stores them as DynamicFields. So far so good. If the newer version reads those entries from the database it does not recognize that those DynamicFields are already defined in the database-definition. When the values are stored again it simply overwrites the previous values because the name-property of the DynamicField is without an _ and the dict which is sent to mongo is updated twice with the same name.

My proposal is to check if the name of the DynamicField without an _ is already in the database definition. If so, that field is used.