#25361: Unpickling of QuerySet fails in presence of abstract intermediate model ----------------------------------------------+-------------------- Reporter: bronger | Owner: nobody Type: Bug | Status: new Component: Database layer (models, ORM) | Version: 1.8 Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Easy pickings: 0 | UI/UX: 0 ----------------------------------------------+-------------------- Consider the following model hierarchy:
{{{ from django.db import models class Pizza(models.Model): timestamp = models.DateTimeField("last modified", auto_now=True) class SpecialPizza(Pizza): class Meta: abstract = True ordering = ["timestamp"] class MyPizza(SpecialPizza): pass class Topping(models.Model): pizza = models.ForeignKey(MyPizza, related_name="toppings") class Meta: ordering = ["pizza"] }}} QuerySet objects containing MyPizza objects with Toppings cannot be pickled and unpickled: {{{ my_pizza = models.MyPizza.objects.create() my_pizza.toppings.add(models.Topping()) pickled = pickle.dumps(my_pizza.toppings.all()) response = pickle.loads(pickled) }}} The traceback is: {{{ Traceback: File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response 132. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in inner 145. return func(*args, **kwargs) File "/tmp/myproject/myproject/myapp/views.py" in test 9. response = pickle.loads(pickled) File "/usr/lib/python2.7/pickle.py" in loads 1383. return Unpickler(file).load() File "/usr/lib/python2.7/pickle.py" in load 858. dispatch[key](self) File "/usr/lib/python2.7/pickle.py" in load_reduce 1134. value = func(*args) File "/usr/local/lib/python2.7/dist- packages/django/db/models/fields/__init__.py" in _load_field 66. return apps.get_model(app_label, model_name)._meta.get_field(field_name) File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py" in get_model 202. return self.get_app_config(app_label).get_model(model_name.lower()) File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py" in get_model 162. "App '%s' doesn't have a '%s' model." % (self.label, model_name)) Exception Type: LookupError at / Exception Value: App 'myapp' doesn't have a 'specialpizza' model. }}} If one removes one of the "ordering" fields, the unpickler uses "MyPizza" instead of "SpecialPizza", which is correct and should always be the case. -- Ticket URL: <https://code.djangoproject.com/ticket/25361> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/050.b12f9bf9d2eeaccbce1643db4a5135a3%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.