Skip to content

Conversation

mriduldhall
Copy link
Contributor

Clarified unique constraints with nulls distinct are ignored for databases besides PostgreSQL 15+. Added warning in unique constraint docs.

Thanks Russell Owen for the report.

Trac ticket number

ticket-36594

Branch description

Expanded error message for UniqueConstraint's nulls_distinct check to clarify that nulls_distinct are ignored for databases besides PostgreSQL 15+. Additionally, converted relevant docs note to warning to make it more obvious.

Checklist

  • This PR targets the main branch.
  • The commit message is written in past tense, mentions the ticket number, and ends with a period.
  • I have checked the "Has patch" ticket flag in the Trac system.
  • I have added or updated relevant tests.
  • I have added or updated relevant docs, including release notes if applicable.
  • I have attached screenshots in both light and dark modes for any UI changes.

Comment on lines 408 to 410
f"{connection.display_name} does not support unique constraints "
"with nulls distinct.",
"with nulls distinct. They are ignored for databases besides "
"PostgreSQL 15+.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would maybe have:

                    f"{connection.display_name} does not support the "
                    "'nulls_distinct' parameter for unique constraints.",

As I think we want to emphasizing that having values for nulls_distinct set is not supported (rather than this being interpreted that nulls_distinct=False might be valid

Note that any changes to the warning needs to be updated in the system check docs:

--- a/docs/ref/checks.txt
+++ b/docs/ref/checks.txt
@@ -438,8 +438,8 @@ Models
   expression and won't be validated during the model ``full_clean()``.
 * **models.W046**: ``<database>`` does not support comments on tables
   (``db_table_comment``).
-* **models.W047**: ``<database>`` does not support unique constraints with
-  nulls distinct.
+* **models.W047**: ``<database>`` does not support the 'nulls_distinct'
+  parameter for unique constraints.
 * **models.E048**: ``constraints/indexes/unique_together`` refers to a
   ``CompositePrimaryKey`` ``<field name>``, but ``CompositePrimaryKey``\s are
   not supported for that option.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parameter -> argument
or perhaps "does not support UniqueConstraint.nulls_distinct."

…ck warning.

Clarified unique constraints with nulls distinct are ignored for
databases besides PostgreSQL 15+. Added warning in unique constraint
docs.

Thanks Russell Owen for the report.
@mriduldhall
Copy link
Contributor Author

I have just pushed out a patch with the improvements. Apologies for the delay.

Copy link
Contributor

@Samriddha9619 Samriddha9619 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants