Opened 17 years ago

Closed 16 years ago

#3188 closed defect (invalid)

OneToOne field - ChangeManipulator looks for related primary key

Reported by: alex@… Owned by: nobody
Component: contrib.admin Version: dev
Severity: normal Keywords:
Cc: alex@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no


I am posting it as bug, I have already tried to post to django-developers, no feedback has been received.

Assume I relate django.contrib.auth.User to Customer using OneToOne relation. If I do this,
I am unable to edit this user via /admin since ChangeManipulator brings up this error:

Exception Type:         KeyError
Exception Value:        'user'
Exception Location:
        /usr/lib64/python2.4/site-packages/django/db/models/ in
save, line 163

Obviously, this is because Manipulator tries to use related field ID as
for ForeignKey, but it
seems to be wrong approach, since with OneToOne field we should
directly search on User.

I have tried to change the code to something like this:

And it works fine for me. I am submitting this as working patch,
but I consider it to be a temp. solution only.

Attachments (1)

patch.diff (2.2 KB ) - added by frankie@… 17 years ago.
Patch in the correct format and in the correct place.

Download all attachments as: .zip

Change History (7)

by frankie@…, 17 years ago

Attachment: patch.diff added

Patch in the correct format and in the correct place.

comment:1 by anonymous, 17 years ago

Cc: alex@… added

Hi Frankie,
Thank you very much for a correct patch. It does work for me well.

comment:2 by Simon G. <dev@…>, 17 years ago

Triage Stage: UnreviewedDesign decision needed

comment:3 by anonymous, 17 years ago

Aha, I see what has been done. It looks my patch has been included here from

The real reasons why I did not included the patch directly here is simple: I fixed the problem without deep understanding of the problem itself. All I did is a quick & dirty fix which fixes the consequence, but I have no idea how the "right" fix should be. Probably only the author of the code have better understanding how the things has been done.

Probably soon all this will be deprecated since the Django will move admin to newforms. Until then this patch can be used by people who are affected by this bug, but including this patch to main tree would be too ugly since the patch ugly itself.... It does "type check" what is considered bad in Python world...

comment:4 by Gary Wilson <gary.wilson@…>, 17 years ago

Has patch: set
Triage Stage: Design decision neededAccepted

Marking this accepted since it is a bug.

comment:5 by Gary Wilson <gary.wilson@…>, 17 years ago

Needs tests: set

Could someone please write a unit test that shows this bug.

comment:6 by Brian Rosner, 16 years ago

Resolution: invalid
Status: newclosed

oldforms is going away and is no longer supported. This should be working now in trunk via newforms. If not it should be reported as a new ticket.

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