From 54cb1a7e160089cea438f50fdb70aaaf6823786e Mon Sep 17 00:00:00 2001 From: Peter Thomassen Date: Fri, 1 Dec 2023 14:12:06 +0100 Subject: [PATCH 1/2] Fixed #35002 -- Made UniqueConstraints with fields respect nulls_distinct. Regression in 595a2abb58e04caa4d55fb2589bb80fb2a8fdfa1. --- django/db/backends/base/schema.py | 2 +- tests/schema/tests.py | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/django/db/backends/base/schema.py b/django/db/backends/base/schema.py index aeb3cde9a4df..f01abf46b084 100644 --- a/django/db/backends/base/schema.py +++ b/django/db/backends/base/schema.py @@ -111,7 +111,7 @@ class BaseDatabaseSchemaEditor: sql_create_unique = ( "ALTER TABLE %(table)s ADD CONSTRAINT %(name)s " - "UNIQUE (%(columns)s)%(deferrable)s" + "UNIQUE%(nulls_distinct)s (%(columns)s)%(deferrable)s" ) sql_delete_unique = sql_delete_constraint diff --git a/tests/schema/tests.py b/tests/schema/tests.py index d1d18bab176d..d44b8e25aaf6 100644 --- a/tests/schema/tests.py +++ b/tests/schema/tests.py @@ -3468,7 +3468,7 @@ def test_func_unique_constraint_nondeterministic(self): editor.add_constraint(Author, constraint) @skipUnlessDBFeature("supports_nulls_distinct_unique_constraints") - def test_unique_constraint_nulls_distinct(self): + def test_unique_constraint_index_nulls_distinct(self): with connection.schema_editor() as editor: editor.create_model(Author) nulls_distinct = UniqueConstraint( @@ -3491,6 +3491,29 @@ def test_unique_constraint_nulls_distinct(self): self.assertNotIn(nulls_distinct.name, constraints) self.assertNotIn(nulls_not_distinct.name, constraints) + @skipUnlessDBFeature("supports_nulls_distinct_unique_constraints") + def test_unique_constraint_nulls_distinct(self): + with connection.schema_editor() as editor: + editor.create_model(Author) + constraint = UniqueConstraint( + fields=["height", "weight"], name="constraint", nulls_distinct=False + ) + with connection.schema_editor() as editor: + editor.add_constraint(Author, constraint) + Author.objects.create(name="", height=None, weight=None) + Author.objects.create(name="", height=1, weight=None) + Author.objects.create(name="", height=None, weight=1) + with self.assertRaises(IntegrityError): + Author.objects.create(name="", height=None, weight=None) + with self.assertRaises(IntegrityError): + Author.objects.create(name="", height=1, weight=None) + with self.assertRaises(IntegrityError): + Author.objects.create(name="", height=None, weight=1) + with connection.schema_editor() as editor: + editor.remove_constraint(Author, constraint) + constraints = self.get_constraints(Author._meta.db_table) + self.assertNotIn(constraint.name, constraints) + @skipIfDBFeature("supports_nulls_distinct_unique_constraints") def test_unique_constraint_nulls_distinct_unsupported(self): # UniqueConstraint is ignored on databases that don't support From 94d495f96042cb7b3a34e09e6bff0d3a9046485f Mon Sep 17 00:00:00 2001 From: Tom Carrick Date: Sun, 3 Dec 2023 14:20:57 +0100 Subject: [PATCH 2/2] Removed unused CSS rules for related widget in RTL. --- django/contrib/admin/static/admin/css/responsive_rtl.css | 5 ----- 1 file changed, 5 deletions(-) diff --git a/django/contrib/admin/static/admin/css/responsive_rtl.css b/django/contrib/admin/static/admin/css/responsive_rtl.css index d23aa8799f5c..33b578484255 100644 --- a/django/contrib/admin/static/admin/css/responsive_rtl.css +++ b/django/contrib/admin/static/admin/css/responsive_rtl.css @@ -35,11 +35,6 @@ background-position: calc(100% - 8px) 9px; } - [dir="rtl"] .related-widget-wrapper-link + .selector { - margin-right: 0; - margin-left: 15px; - } - [dir="rtl"] .selector .selector-filter label { margin-right: 0; margin-left: 8px;