Opened 9 years ago

Closed 7 years ago

#3188 closed defect (invalid)

OneToOne field - ChangeManipulator looks for related primary key

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

Description

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/manipulators.py 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.

http://dpaste.com/4045/

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

http://dpaste.com/3858/

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@… 9 years ago.
Patch in the correct format and in the correct place.

Download all attachments as: .zip

Change History (7)

Changed 9 years ago by frankie@…

Patch in the correct format and in the correct place.

comment:1 Changed 8 years ago by anonymous

  • Cc alex@… added

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

comment:2 Changed 8 years ago by Simon G. <dev@…>

  • Triage Stage changed from Unreviewed to Design decision needed

comment:3 Changed 8 years ago by anonymous

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

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 Changed 8 years ago by Gary Wilson <gary.wilson@…>

  • Has patch set
  • Triage Stage changed from Design decision needed to Accepted

Marking this accepted since it is a bug.

comment:5 Changed 8 years ago by Gary Wilson <gary.wilson@…>

  • Needs tests set

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

comment:6 Changed 7 years ago by brosner

  • Resolution set to invalid
  • Status changed from new to closed

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