Project

Profile

Help

Task #1220

Updated by bmbouter over 8 years ago

Using any kind of You can use a mongoengine model (mongoengine or not) in a migration is problematic. Models change over time, migration, but migrations should always remain the same. This task is to document that migrations should use PyMongo directly and never use a model of any kind. 

 In addition to the maintainability problem, mongoengine models don't even work as expected because the save() handler won't work as it does in other parts of the code. Normally save() moves files into place and in the puppet case calculates checksums, but at pulp-manage-db time none of those things work. This issue used 

 These signals get wired up when the "PluginManager is instantiated":https://github.com/pulp/pulp/blob/e2c78edf42e21852005d67501ca3e4e01e85122f/server/pulp/server/db/manage.py#L128. I think this fix would be to contain a detailed description of why, move it to starting just after "initializing the logger here":https://github.com/pulp/pulp/blob/e2c78edf42e21852005d67501ca3e4e01e85122f/server/pulp/server/db/manage.py#L143 

 Migrations probably shouldn't be using models because models change over time and migrations should, but you can look at the diff history if you want they are used use with caution! 

 I did test to see why if calling PluginManager multiple times would cause the pre_save handler to be called multiple times, but with mongoengine 0.9.0 it does not per this doesn't work. little test: 

 <pre> 
 from mongoengine import Document, StringField, signals, connect 

 connect('tumblelog') 


 def update_modified(*args, **kwargs): 
     print 'I ran' 


 class Record(Document): 
     foo = StringField() 

 signals.pre_save.connect(update_modified) 
 signals.pre_save.connect(update_modified) 
 signals.pre_save.connect(update_modified) 


 Record(foo='asdf').save() 
 </pre> 

 Which when I run foo.py says: 

 <pre> 
 I ran 
 </pre>

Back