﻿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
35594	Add support for non-distinct NULL expressions to UniqueConstraint.validate()	Mark Gensler	Simon Charette	"Expressions which evaluate to `NULL` within `UniqueConstraint(*expressions, nulls_distinct=False)` are still treated as distinct by `UniqueConstraint.validate()`. This means a `ValidationError` is not raised when it should be.

Similarly, if the database connection uses `interprets_empty_strings_as_nulls` this is also ignored by `.validate()`.

Should #35575 be merged, this problem would also extend to any `GeneratedField` included in `UniqueConstraint(fields=[...], nulls_distinct=False)`.

E.g.

{{{
class Book(models.Model):
    name = CharField(max_length=255, null=True, blank=True)

    class Meta:
        constraints = [
            UniqueConstraint(F(""name""), nulls_distinct=False, name=""book_name_null_unique"")
        ]
}}}
then
{{{
> Book.objects.create(name=None)
> book = Book(name=None)
> book.full_clean() # Should raise a `ValidationError` but doesn't.
> book.save()  # The database raises a `UniqueViolation`.
}}}

This ticket was raised following discussion in https://github.com/django/django/pull/18356#pullrequestreview-2166340541"	Bug	closed	Database layer (models, ORM)	5.0	Release blocker	fixed	unique constraint nulls_distinct validation expressions	Simon Charette	Ready for checkin	1	0	0	0	0	0
