#27594 closed Bug (fixed)
Reverse one to one related object populated from incorrect query columns
| Reported by: | Daniel Hillier | Owned by: | Daniel Hillier |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| Severity: | Normal | Keywords: | onetoone reverse |
| Cc: | daniel.hillier@… | Triage Stage: | Accepted |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Extracting data for the related object from a queryset with a self referential one to one field gets the wrong data (incorrect columns) from the query when using a select_related with the reverse field.
The incorrect columns are introduced by the sqlcompiler mistaking the reverse select_related path as a part of a multiple concrete model inheritance structure.
Change History (7)
comment:1 by , 9 years ago
| Description: | modified (diff) |
|---|---|
| Owner: | changed from to |
comment:2 by , 9 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:3 by , 9 years ago
| Patch needs improvement: | set |
|---|
I left comments for improvement on the PR. Please uncheck "Patch needs improvement" after updating. A single squashed commit is fine. Thanks!
comment:4 by , 9 years ago
| Patch needs improvement: | unset |
|---|
Thanks for the review!
I've simplified the way I fixed the bug and implemented your suggestions.
I think the heart of the bug was the definition of from_parent. A relationship between two models isn't from_parent if the two model classes are the same. I've updated how from_parent is defined to reflect that corner case.
Happy to incorporate any further changes you may have.
The proposed fix tests for self-referential relationships and avoids the multiple concrete model inheritance path in those instances.
PR