Add manipulator fails when unique together fields added
|Reported by:||Owned by:||nobody|
|Severity:||Keywords:||admin maniuplator add iexact fail nfa-blocker|
|Cc:||m.gajda@…, cmawebsite@…||Triage Stage:||Accepted|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
Below some code, to ilustrate an issue I found:
class A( models.Model ): foo = models.CharField() class B( models.Model ): x = models.ForeignKey( A ) y = models.ForeignKey( B ) class Meta: unique_together = ( ( x , y ) , )
For this piece of code, after adding some objects for "A" model using admin there is no possibility to add something to model "B' (using this same admin). In this case database backed (PostgreSQL in my case) returns error message worrying about wrong comparison operator used to looking for already added object pair.
It raises this error because it tries to compares "y" field using proper "pk" lookup, but for "x" field it invokes "iexact" lookup method. The second one fails, because it should be used only for strings.
After some code investigation I found some weird pair of assigments in file "django/db/models/manipulators.py", which I changed according to attached patch. Now everything seems to work correctly.
Change History (9)
comment:1 Changed 9 years ago by
|Keywords:||admin maniuplator add iexact fail added|
|Summary:||Add manipulator fails → Add manipulator fails when unique together fields added|
comment:3 Changed 8 years ago by
|Component:||Core framework → Admin interface|
|Status:||closed → reopened|
|Triage Stage:||Unreviewed → Accepted|
|Version:||SVN → newforms-admin|