#24851 closed Bug (fixed)
Regression in reverse one-to-one field in list_display
Reported by: | Eduardo Rivas | Owned by: | Tim Graham |
---|---|---|---|
Component: | contrib.admin | Version: | 1.8 |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Including reverse one-to-one relations in list_display
or fields
in a ModelAdmin
breaks the "change_list" and "change" admin views.
The "change" view raises a FieldError
saying the reverse one-to-one field is unknown. The "change_list" raises AttributeError
: 'OneToOneRel' object has no attribute 'rel'.
I've setup a small test app here: https://gitlab.com/jerivas/one-to-one-bug.
To reproduce:
- Clone the repo
- Install deps from requirements.txt
- Start the development server
- Visit the admin. User/pass: proj/proj
- Both the Car and Engine admins should work
- Uncomment lines 7 & 8 from
cars/admin.py
- Both the "change_list" and "change" views of the Car admin are now broken. The Engine admin continues to work as expected.
This worked normally in 1.6, and I just found it while updating a project from 1.6 to 1.8. I don't know if the bug was introduced in 1.7 or 1.8.
Attachments (1)
Change History (10)
comment:1 by , 9 years ago
Component: | Uncategorized → contrib.admin |
---|---|
Severity: | Normal → Release blocker |
Summary: | Reverse one-to-one relations break the admin. → Regression in reverse one-to-one field in list_display |
Triage Stage: | Unreviewed → Accepted |
by , 9 years ago
Attachment: | 24851-test.diff added |
---|
comment:2 by , 9 years ago
Whoops, you're right, I was only using list_display
in 1.6. Sorry about that.
However, wouldn't it be appropriate to support reverse one-to-one relations in fields
? I see three possible scenarios:
- Reverse one-to-one relations fully supported in
fields
. - Supported only when they appear in
readonly_fields
. - Unsupported, but they raise a more useful exception and is explained in the docs. The current exception says the one-to-one field is unknown to the model, which is confusing and gives the impression the user has made a typo in
fields
. IMOImproperlyConfigured
would be better.
If you think any of the above have the potential of flying as a feature request, I can open a new ticket.
comment:3 by , 9 years ago
I don't think it could be easily supported in fields
as that would require saving the related instance. readonly_fields
support might be doable. I think a natural suggestion for the error message would be to suggest to use an inline.
comment:4 by , 9 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:8 by , 9 years ago
I'm having an extremely similar issue, but when the reverse OneToOne is in the readonly
list, rather than fields
. Is it possible it's the same issue? The above mentioned test app seems to be gone.
comment:9 by , 9 years ago
This has been fixed in Django 1.8.3+ so if you can reproduce your problem there, please open a new ticket with details. Thanks.
Reproduced the
list_display
crash and bisected the regression in 1.8 at fb48eb05816b1ac87d58696cdfe48be18c901f16. It's fixed in master by 8f30556329b64005d63b66859a74752a0b261315 but we should fix it in 1.8 too. Attaching a regression test.As for the change view error, that seems to be reproducible on stable/1.6.x and stable/1.4.x so I don't think it's a regression or a bug.