Unpickling of dynamic model classes broken in 1.5
|Reported by:||Anssi Kääriäinen||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.5|
|Cc:||Simon Charette||Triage Stage:||Accepted|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The commit 146aff3bac974e56ec8cb597c2720d1cd4f77b26 broke unpickling of dynamically created models. This was reported in django-users thread http://groups.google.com/group/django-users/browse_thread/thread/1eee4a4d5098bfc5.
The problem is that deferred classes aren't only possible source of dynamically created class in Django. ManyToMany through class are dynamically created and in addition dynamic classes are possible in user code. My understanding is that user code dynamic classes should be supported, too.
I am not sure how to trigger this bug using standard Django models and fields. The django-users thread mentions this:
So for example, I have an instance of a Student, which has a ForeignKey to Book, which in turn has a ManyToMany to Author. If I try and cache my Student instance, I get that pickling error.
but I haven't tested this.
I think resurrecting the simple_class_factory path of code instead of using
super.__reduce__ for the non deferred case is the right fix. Of course, the code comments need fixing, too, so just reverting the commit isn't a good idea.
Note that I haven't done any actual testing (no Django available on this machine...), so I will leave this unreviewed until I (or somebody else) will reproduce this using Django 1.5.
Change History (9)
comment:7 Changed 4 years ago by
|Status:||closed → new|
|Triage Stage:||Ready for checkin → Accepted|