Unpickling of dynamic model classes broken in 1.5
|Reported by:||akaariai||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.5|
|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:1 Changed 3 years ago by charettes
- Cc charettes added
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted
comment:6 Changed 3 years ago by Anssi Kääriäinen <akaariai@…>
- Resolution set to fixed
- Status changed from new to closed
comment:7 Changed 3 years ago by akaariai
- Resolution fixed deleted
- Status changed from closed to new
- Triage Stage changed from Ready for checkin to Accepted