As far as I can tell, if one has three models, GrandparentModel,
ParentModel, and ChildModel, in which GrandparentModel defines a
unique field unique_field, Childmodel.validate_unique() will not check
the uniqueness of unique_field.

The fields to check are determined by ChildModel._get_unique_checks(),
which looks at ChildModel._meta.local_fields and then looks at each of
ChildModel's parent models' local fields (namely
ParentModel._meta.local_fields). But
GrandparentModel._meta.local_fields doesn't appear to be checked.
Since unique_field only appears in
GrandparentModel._meta.local_fields, it is left out of the check.

The code in question is: 
http://code.djangoproject.com/browser/django/trunk/django/db/models/base.py#L648

Am I reading this correctly? I could very much be wrong. In the app
I'm currently working, I verified that the analogue of unique_field is
not returned by ChildModel._get_unique_check(), though there's a
chance something else is going wrong. I know the field is returned by
both ParentModel._get_unique_check() and
GrandparentModel._get_unique_check(). In my case, full_clean()
succeeds when testing field duplication, but save() fails with:

IntegrityError: column unique_field is not unique

Is this a bug?

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to