1

EDIT:

  1. I fixed a few typos below
  2. I added a zip file to a small app to demonstrate this problem here. You can download it and run python manage.py testselectrelateddefer after you syncdb and migrate.
  3. I added a couple of observations below

I fix I am having a multi-table inheritance model as following:

class Image(models.Model):
    # other fields are removed for simplicity
    image = models.ImageField(upload_to="image")


class ItemImage(Image):
    # other fields are removed for simplicity
    display_name = models.CharField(max_length=50)

I want to query this model and defer the image field when I don't need the image (which is in the parent model). My container model looks somewhat like this:

class Item(models.Model):
    item_image = models.OneToOneField(ItemImage)

The query looks like this:

test.models.Item.objects.select_related('item_image').defer("item_image__image").get(pk=1)

Django is throwing an error saying:

ValueError: u'image_ptr_id' is not in the list.

Django does not throw an error if I query for the field that is not in the parent model:

test.models.Item.objects.select_related('item_image').defer("item_image__display_name").get(pk=1)

Do you know how to fix this issue?

Observations:

  1. As I mentioned above, this only happens if the deferred field is in the parent model; it does not happen if the deferred field is in the child model.
  2. It does not matter if the parents field have any extra field.
nlhma
  • 81
  • 1
  • 3
  • Can you post your exact model structure? It'll help us to try and debug your error. – schillingt Apr 05 '14 at 01:00
  • @schillingt: not sure what you would like further. I added a zip file of a test program you can run to see the problem. – nlhma Apr 05 '14 at 17:25

0 Answers0