#23370 closed Bug (fixed)
defer() with inherited models fails
Reported by: | Akis Kesoglou | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | akiskesoglou@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Let's say I have two models: Post(models.Model)
and 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
Attachments (2)
Change History (19)
by , 10 years ago
Attachment: | testdefer.zip added |
---|
comment:1 by , 10 years ago
Cc: | added |
---|
by , 10 years ago
Attachment: | 23370-test.diff added |
---|
comment:2 by , 10 years ago
Triage Stage: | Unreviewed → Accepted |
---|
Reproduced with the attached test case for Django's test suite.
comment:4 by , 10 years ago
Just tested Vladimiroff's branch but doesn't fix this issue. The bugs seem similar though.
comment:5 by , 10 years ago
Easy pickings: | set |
---|---|
Has patch: | set |
comment:8 by , 10 years ago
Unless this is a regression in 1.6, then the backporting rules says that we shouldn't backport this.
comment:9 by , 10 years ago
The bug must have been introduced in this commit, which I believe was made on the road to 1.6. What do you think? I'm not trying to put pressure, but *if* there's going to be another 1.6 release, it'd be nice to have this included.
comment:10 by , 10 years ago
Easy pickings: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
Check if the test passes on 1.5. Ready for final ORM review. If it's backported, it'll need release notes though.
comment:11 by , 10 years ago
I also confirm that this is a regression from 1.5 to 1.6 which would warrant the backporting.
Using git bisect, I found that the commit that introduced the regression is actually 6ebf115206289bce8f3d86318871faac13d6e835.
Thanks.
comment:12 by , 10 years ago
Updated the PR based on timgraham's comment. Ran tests -- all pass.
I'll run the test on 1.5 and create a separate PR for 1.6 and let you know.
comment:13 by , 10 years ago
Probably don't need a separate PR. We have scripts to do the backporting.
comment:15 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Test project