Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#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


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:

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/
  • 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)

24851-test.diff (989 bytes ) - added by Tim Graham 9 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 by Tim Graham, 9 years ago

Component: Uncategorizedcontrib.admin
Severity: NormalRelease blocker
Summary: Reverse one-to-one relations break the admin.Regression in reverse one-to-one field in list_display
Triage Stage: UnreviewedAccepted

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.

by Tim Graham, 9 years ago

Attachment: 24851-test.diff added

comment:2 by Eduardo Rivas, 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. IMO ImproperlyConfigured 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 Tim Graham, 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 Tim Graham, 9 years ago

Owner: changed from nobody to Tim Graham
Status: newassigned

comment:5 by Tim Graham, 9 years ago

Has patch: set

comment:6 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In 2456276b:

[1.8.x] Fixed #24851 -- Fixed crash with reverse one-to-one relation in ModelAdmin.list_display

comment:7 by Tim Graham <timograham@…>, 9 years ago

In ad0f0daf:

Fixed #24851 -- Fixed crash with reverse one-to-one relation in ModelAdmin.list_display

Forwardport of 2456276b0250c9f21d580ca6c3f3c86345ad6370 from stable/1.8.x

comment:8 by Hugo Osvaldo Barrera, 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 Tim Graham, 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.

Note: See TracTickets for help on using tickets.
Back to Top