defer() with inherited models fails
|Reported by:||Akis Kesoglou||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||master|
|Cc:||akiskesoglou@…||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Let's say I have two models:
Article(Post) and some data.
Now if I evaluate the query set
Post.objects.select_related('article').defer('article__somefield') it will fail with:
... File "django/db/models/query.py", line 1457, in get_cached_row if (fields[pk_idx] is None or IndexError: tuple index out of range
This prevents us from using
defer() to optimise our queries to defer loading of large TEXT fields when showing lists of posts.
This is present in master [a81af7f49de7ff3f51f111de28ed3a682f67ea89] and (with a similar traceback) since at least Django 1.6.
I have attached a test project that demonstrates the bug. Add the project to path and run:
$ ./manage.py migrate $ ./manage.py testdefer