﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
2019	manipulator_validator_unique_together does not work correctly	imunitic@…	Adrian Holovaty	"Hello,my name is Ivica Munitic and i come from Croatia.
English is not my primary language so sorry if a don't spell some words correctly :)

I've been working on some small application and I think i found a bug.
The problem is with the {{{ manipulator_validator_unique_together }}} function.
My model class where the problem occurres looks like this:

{{{
class Criteria(models.Model):
    subject = models.ForeignKey(Subject)
    professor = models.ForeignKey(Professor)
    activity_type = models.ForeignKey(ActivityType)
    coefficient = models.FloatField(max_digits=3, decimal_places=2, validator_list=[range_validator])
    minresult = models.FloatField('Minimal result', max_digits=3, decimal_places=2, validator_list=[range_validator])
    created = models.DateTimeField('created', auto_now_add=True)

    def __str__(self):
        return ""%s, %s, %s"" % (self.subject.name, self.professor.get_fullname(), self.activity_type.name)
    
    class Meta:
        unique_together = (('subject', 'professor', 'activity_type'),)
        
    class Admin:
        date_hierarchy = 'created'
        list_display = ('subject', 'professor', 'activity_type', 'created')
        list_filter = ('created', 'activity_type' )
        ordering = ['-created']
}}}

As you can see I added a {{{ unique_together }}} field.
I the admin site when i try to save a duplicate i get an exception not a {{{ ValidationError }}} as expected.
I debugged a bit and found the problem to be in this piece of code (django/db/models/manipulators.py:286):
{{{
        field_val = all_data.get(f.attname, None)
        if field_val is None:
            # This will be caught by another validator, assuming the field
            # doesn't have blank=True.
            return
}}}
{{{ f.attname }}} for the {{{ self.professor }}} field is {{{ professor_id }}} but {{{ all_data }}} dictionary has a {{{ professor }}} not a {{{ professor_id }}}.
{{{ manipulator_validator_unique_together }}} just returns and does not raise a {{{ ValidationError }}}.
If I change {{{ f.attname }}} to {{{ f.name }}} then it works but i don't know if this is correct.

So, this is my first ticket :)
I hope it is a good one :))"	defect	closed	contrib.admin	dev	normal	duplicate			Unreviewed	0	0	0	0	0	0
