I’m using ZODB which, as I understand it, uses pickle to store class instances. I’m doing a bit of refactoring where I want to split my models.py file into several files. However, if I do this, I don’t think pickle will be able to find the class definitions, and thus won’t be able to load the objects that I already have stored in the database. What’s the best way to handle this problem?
I’m using ZODB which, as I understand it, uses pickle to store class instances.
Share
You can create aliases; because one
models.pymodules is being split into multiple new modules you can only do this by importing your classes into the old location.Both methods cause new copies of your instance pickles to refer to the new location; if you can force a write on all instances of the moved classes you don’t need to retain the aliases. You can do this by setting
_p_changedtoTrueon your instances that you want to be written again.So, to create the aliases, import your moved classes in the old location:
If you only rename a module (so the same classes all are found in one new location, could be a set of imports themselves), you can also create a
sys.modulesentry for the old name: