Opened 10 years ago

Closed 10 years ago

Last modified 9 years ago

#514 closed defect (fixed)

[patch] Traceback in admin when adding an object containing a OneToOneField.

Reported by: mmarshall Owned by: adrian
Component: contrib.admin Version: 1.0
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Working with objects that have a OneToOneField in the admin works fine when you click on "change" and then select one from the list. However, if you click on "Add", saving the object results in a traceback similar to this (with the rel_name of 'node'):

There's been an error:

Traceback (most recent call last):

<snip>

  File "/usr/lib/python2.4/site-packages/django/core/meta/fields.py", line 40, in manipulator_validator_unique
    old_obj = opts.get_model_module().get_object(**{'%s__exact' % f.name: field_data})

<snip>

TypeError: got unexpected keyword argument 'node__exact'

A trivial patch solves the problem:

Index: django_src/django/core/meta/fields.py
===================================================================
--- django_src/django/core/meta/fields.py       (revision 642)
+++ django_src/django/core/meta/fields.py       (working copy)
@@ -37,7 +37,7 @@
 def manipulator_validator_unique(f, opts, self, field_data, all_data):
     "Validates that the value is unique for this field."
     try:
-        old_obj = opts.get_model_module().get_object(**{'%s__exact' % f.name: field_data})
+        old_obj = opts.get_model_module().get_object(**{'%s__id__exact' % f.name: field_data})
     except ObjectDoesNotExist:
         return
     if hasattr(self, 'original_object') and getattr(self.original_object, opts.pk.column) == getattr(old_obj, opts.pk.column):

MWM

Change History (2)

comment:1 Changed 10 years ago by mmarshall

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

Fixed in [643].

MWM

comment:2 Changed 9 years ago by anonymous

  • milestone Version 1.0 deleted

Milestone Version 1.0 deleted

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