Skip to content

Unique validators don't treat NULL the same as Django or Postgres #2452

@kylemacfarlane

Description

@kylemacfarlane

When it comes to uniqueness, Postgres (and others) doesn't consider NULL to be equal to NULL and so duplicate NULLs are OK. However DRF merely checks for the existence of rows in a database and raises uniqueness validation errors even when it shouldn't.

I had a look at how Django's model forms deal with it and it seems like if any of the fields to be checked are None then unique validation is simply completely skipped: https://github.com/django/django/blob/f8e4e4a935512aedf815f6aee85bc797b498ea75/django/forms/models.py#L667

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions