﻿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
14067	_perform_unique_checks, _perform_date_checks broken for subclasses	minijb	nobody	"fields marked unique on base classes are validated wrong on subclasses.

The broken part is in django/db/models/base.py:
{{{
            qs = model_class._default_manager.filter(**lookup_kwargs)

            # Exclude the current object from the query if we are editing an
            # instance (as opposed to creating a new one)
            if not getattr(self, '_adding', False) and self.pk is not None:
                qs = qs.exclude(pk=self.pk)
}}}


Specifically, the exclude statement filtering on model_class.pk=self.pk does not consider that self (an instance of the subclass) has a different pk to model_class (the base class). This results in the wrong pk being used to exclude on.

This could instead filter on self's value for model_classes pk like so:

{{{
            qs = model_class._default_manager.filter(**lookup_kwargs)

            # Exclude the current object from the query if we are editing an
            # instance (as opposed to creating a new one)
            if not getattr(self, '_adding', False) and self.pk is not None:
                qs = qs.exclude(pk=getattr(self, model_class._meta.pk.name))
}}}


"		closed	Database layer (models, ORM)	1.2		invalid			Unreviewed	0	0	0	0	0	0
