Opened 19 years ago

Closed 19 years ago

Last modified 18 years ago

#514 closed defect (fixed)

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

Reported by: mmarshall Owned by: Adrian Holovaty
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: no UI/UX: no

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 by mmarshall, 19 years ago

Resolution: fixed
Status: newclosed

Fixed in [643].

MWM

comment:2 by (none), 18 years ago

milestone: Version 1.0

Milestone Version 1.0 deleted

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