Django

Code

Ticket #3188 (closed: invalid)

Opened 2 years ago

Last modified 4 months ago

OneToOne field - ChangeManipulator looks for related primary key

Reported by: alex@halogen-dg.com Assigned to: nobody
Milestone: Component: django.contrib.admin
Version: SVN Keywords:
Cc: alex@halogen-dg.com Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 1 Patch needs improvement: 0

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

patch.diff (2.2 kB) - added by frankie@grimboy.co.uk on 12/27/06 08:22:16.
Patch in the correct format and in the correct place.

Change History

12/27/06 08:22:16 changed by frankie@grimboy.co.uk

  • attachment patch.diff added.

Patch in the correct format and in the correct place.

01/30/07 03:12:20 changed by anonymous

  • cc set to alex@halogen-dg.com.

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

01/30/07 03:25:43 changed by Simon G. <dev@simon.net.nz>

  • stage changed from Unreviewed to Design decision needed.

01/30/07 10:43:55 changed 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...

01/30/07 11:52:21 changed by Gary Wilson <gary.wilson@gmail.com>

  • has_patch set to 1.
  • stage changed from Design decision needed to Accepted.

Marking this accepted since it is a bug.

02/26/07 12:22:47 changed by Gary Wilson <gary.wilson@gmail.com>

  • needs_tests set to 1.

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

08/01/08 10:38:54 changed by brosner

  • status changed from new to closed.
  • resolution set to invalid.

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.


Add/Change #3188 (OneToOne field - ChangeManipulator looks for related primary key)




Change Properties
Action