[Django] #35002: nulls_distinct not honored for ALTER

43 views
Skip to first unread message

Django

unread,
Nov 29, 2023, 12:28:14 PM11/29/23
to django-...@googlegroups.com
#35002: nulls_distinct not honored for ALTER
-------------------------------------+-------------------------------------
Reporter: Peter | Owner: nobody
Thomassen |
Type: Bug | Status: new
Component: Database | Version: 5.0
layer (models, ORM) |
Severity: Release | Keywords:
blocker |
Triage Stage: | Has patch: 1
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
The SQL template for creating uniqueness constraints
(BaseDatabaseSchemaEditor.sql_create_unique) does not include the
`nulls_distinct` field necessary to support #34701.

As a result, adding a UNIQUE NULLS NOT DISTINCT on migration will end up
with standard UNIQUE constraint.

Replacing

{{{
"UNIQUE (%(columns)s)%(deferrable)s"
}}}

with

{{{
"UNIQUE%(nulls_distinct)s (%(columns)s)%(deferrable)s"
}}}

on line 114 (5.0rc1) worked for me. I'll be happy to create a PR for that.


Also, I noticed that the `include` field does not appear to be rendered in
this template as well, although the UniqueConstraint class does have an
`include` argument. I wonder if it should also be included there, as
follows (inspired by the sql_create_unique_index template, which I think
should only differ w.r.t. to the condition field):

{{{
"UNIQUE%(nulls_distinct)s (%(columns)s)%(include)s%(deferrable)s"
}}}

I picked "release blocker" because it's a new feature that's broken, not a
random bug unrelated to this release. I hope that was right.

--
Ticket URL: <https://code.djangoproject.com/ticket/35002>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 29, 2023, 2:52:54 PM11/29/23
to django-...@googlegroups.com
#35002: nulls_distinct not honored for ALTER
-------------------------------------+-------------------------------------
Reporter: Peter Thomassen | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* stage: Unreviewed => Accepted


Comment:

Definitely a release blocker thanks for testing against the release
candidate.

Please submit a PR with the proposed changes and a regression test. I'd
suggest making the `includes` change in a distinct commit as this feature
was added in 3.2 and thus I don't think it will qualify for a backport.

--
Ticket URL: <https://code.djangoproject.com/ticket/35002#comment:1>

Django

unread,
Nov 29, 2023, 3:10:27 PM11/29/23
to django-...@googlegroups.com
#35002: nulls_distinct not honored for ALTER
-------------------------------------+-------------------------------------
Reporter: Peter Thomassen | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* has_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/35002#comment:2>

Django

unread,
Nov 30, 2023, 3:53:22 AM11/30/23
to django-...@googlegroups.com
#35002: nulls_distinct not honored for ALTER
-------------------------------------+-------------------------------------
Reporter: Peter Thomassen | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak):

Peter, Do you have time today or tomorrow to work on this? The final 5.0
release is scheduled for Monday, so we're in a hurry. If you don't have
time, I can handle it.

--
Ticket URL: <https://code.djangoproject.com/ticket/35002#comment:3>

Django

unread,
Nov 30, 2023, 4:14:05 AM11/30/23
to django-...@googlegroups.com
#35002: nulls_distinct not honored for ALTER
-------------------------------------+-------------------------------------
Reporter: Peter Thomassen | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Peter Thomassen):

I should be able to do it tomorrow.

--
Ticket URL: <https://code.djangoproject.com/ticket/35002#comment:4>

Django

unread,
Nov 30, 2023, 4:14:05 AM11/30/23
to django-...@googlegroups.com
#35002: nulls_distinct not honored for ALTER
-------------------------------------+-------------------------------------
Reporter: Peter Thomassen | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Peter Thomassen):

I should be able to do it tomorrow.

--
Ticket URL: <https://code.djangoproject.com/ticket/35002#comment:5>

Django

unread,
Nov 30, 2023, 5:45:48 AM11/30/23
to django-...@googlegroups.com
#35002: nulls_distinct not honored for ALTER
-------------------------------------+-------------------------------------
Reporter: Peter Thomassen | Owner: Peter
| Thomassen
Type: Bug | Status: assigned

Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: nobody => Peter Thomassen
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/35002#comment:6>

Django

unread,
Dec 1, 2023, 7:23:22 AM12/1/23
to django-...@googlegroups.com
#35002: nulls_distinct not honored for ALTER
-------------------------------------+-------------------------------------
Reporter: Peter Thomassen | Owner: Peter
| Thomassen
Type: Bug | Status: assigned
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Peter Thomassen):

FYI, I am on it. -- I found that the `includes` field missing in this
template isn't a bug, because when that modifier is given, another
template is used (`sql_create_unique_index`). The patch will thus contain
only the fix for `sql_create_unique`.

--
Ticket URL: <https://code.djangoproject.com/ticket/35002#comment:7>

Django

unread,
Dec 1, 2023, 8:18:37 AM12/1/23
to django-...@googlegroups.com
#35002: nulls_distinct not honored for ALTER
-------------------------------------+-------------------------------------
Reporter: Peter Thomassen | Owner: Peter
| Thomassen
Type: Bug | Status: assigned
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Peter Thomassen):

* has_patch: 0 => 1


Comment:

Patch is here: https://github.com/django/django/pull/17567

Note the comment there regarding the second test.

--
Ticket URL: <https://code.djangoproject.com/ticket/35002#comment:8>

Django

unread,
Dec 3, 2023, 6:30:03 AM12/3/23
to django-...@googlegroups.com
#35002: nulls_distinct not honored for ALTER
-------------------------------------+-------------------------------------
Reporter: Peter Thomassen | Owner: Peter
| Thomassen
Type: Bug | Status: assigned
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/35002#comment:9>

Django

unread,
Dec 3, 2023, 8:12:31 AM12/3/23
to django-...@googlegroups.com
#35002: nulls_distinct not honored for ALTER
-------------------------------------+-------------------------------------
Reporter: Peter Thomassen | Owner: Peter
| Thomassen
Type: Bug | Status: closed

Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"54cb1a7e160089cea438f50fdb70aaaf6823786e" 54cb1a7e]:
{{{
#!CommitTicketReference repository=""
revision="54cb1a7e160089cea438f50fdb70aaaf6823786e"
Fixed #35002 -- Made UniqueConstraints with fields respect nulls_distinct.

Regression in 595a2abb58e04caa4d55fb2589bb80fb2a8fdfa1.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/35002#comment:10>

Django

unread,
Dec 3, 2023, 8:12:59 AM12/3/23
to django-...@googlegroups.com
#35002: nulls_distinct not honored for ALTER
-------------------------------------+-------------------------------------
Reporter: Peter Thomassen | Owner: Peter
| Thomassen
Type: Bug | Status: closed
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"cb013fc7d9be5faf59f79b6e59ab04e751d05a16" cb013fc]:
{{{
#!CommitTicketReference repository=""
revision="cb013fc7d9be5faf59f79b6e59ab04e751d05a16"
[5.0.x] Fixed #35002 -- Made UniqueConstraints with fields respect
nulls_distinct.

Regression in 595a2abb58e04caa4d55fb2589bb80fb2a8fdfa1.

Backport of 54cb1a7e160089cea438f50fdb70aaaf6823786e from main
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/35002#comment:11>

Reply all
Reply to author
Forward
0 new messages