﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
25361	Unpickling of QuerySet fails in presence of abstract intermediate model	Torsten Bronger	nobody	"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."	Bug	closed	Database layer (models, ORM)	1.8	Normal	fixed		bronger@…	Accepted	0	0	0	0	0	0
