[Django] #35992: Migrations crash on constraints/indexes with CompositePrimaryKey.

17 views
Skip to first unread message

Django

unread,
Dec 9, 2024, 5:55:52 PM12/9/24
to django-...@googlegroups.com
#35992: Migrations crash on constraints/indexes with CompositePrimaryKey.
-------------------------------------+-------------------------------------
Reporter: Mariusz | Owner: Mariusz Felisiak
Felisiak |
Type: Bug | Status: assigned
Component: Database | Version: dev
layer (models, ORM) |
Severity: Release | Keywords:
blocker |
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I've created a sample project that tries to add `UniqueConstraint` with a
`CompositePrimaryKey`. Unfortunately, it crashes with programming error
because `CompositePrimaryKey` is resolved to tuple, e.g.
{{{#!sql
CREATE UNIQUE INDEX "uq_mix" ON "test373composite_release" (("version",
"name"));
}}}

{{{
File "/ticket_373_uq_composite/lib/python3.12/site-
packages/psycopg/cursor.py", line 97, in execute
raise ex.with_traceback(None)
django.db.utils.ProgrammingError: syntax error at or near ","
LINE 1: ..."uq_mix" ON "test373composite_release" (("version", "name"))
^
}}}

I've attached a sample project. I can prepare a patch in the coming days.
--
Ticket URL: <https://code.djangoproject.com/ticket/35992>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 9, 2024, 5:56:09 PM12/9/24
to django-...@googlegroups.com
#35992: Migrations crash on constraints/indexes with CompositePrimaryKey.
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* Attachment "ticket_373_uq_composite.zip" added.

Django

unread,
Dec 10, 2024, 2:08:02 AM12/10/24
to django-...@googlegroups.com
#35992: Migrations crash on constraints/indexes with CompositePrimaryKey.
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Database layer | Version: dev
(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 Sarah Boyce):

* stage: Unreviewed => Accepted

Comment:

Thank you for testing!
--
Ticket URL: <https://code.djangoproject.com/ticket/35992#comment:1>

Django

unread,
Dec 10, 2024, 3:51:22 PM12/10/24
to django-...@googlegroups.com
#35992: Migrations crash on constraints/indexes with CompositePrimaryKey.
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Database layer | Version: dev
(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 Mariusz Felisiak):

* has_patch: 0 => 1

Comment:

[https://github.com/django/django/pull/18915 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/35992#comment:2>

Django

unread,
Dec 11, 2024, 3:58:19 PM12/11/24
to django-...@googlegroups.com
#35992: Migrations crash on constraints/indexes with CompositePrimaryKey.
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Database layer | Version: dev
(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
-------------------------------------+-------------------------------------
Comment (by Mariusz Felisiak):

Alternative [https://github.com/django/django/pull/18922 PR].
--
Ticket URL: <https://code.djangoproject.com/ticket/35992#comment:3>

Django

unread,
Dec 17, 2024, 4:27:49 AM12/17/24
to django-...@googlegroups.com
#35992: Migrations crash on constraints/indexes with CompositePrimaryKey.
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Database layer | Version: dev
(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 Sarah Boyce):

* stage: Accepted => Ready for checkin

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

Django

unread,
Dec 17, 2024, 4:28:49 AM12/17/24
to django-...@googlegroups.com
#35992: Migrations crash on constraints/indexes with CompositePrimaryKey.
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: closed
Component: Database layer | Version: dev
(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 Sarah Boyce <42296566+sarahboyce@…>):

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

Comment:

In [changeset:"2249370c8611d97f8bdb6003fb7b4d8fd3646202" 2249370c]:
{{{#!CommitTicketReference repository=""
revision="2249370c8611d97f8bdb6003fb7b4d8fd3646202"
Fixed #35992, Fixed #35997 -- Added system check for CompositePrimaryKeys
in Meta.indexes/constraints/unique_together.

CompositePrimaryKeys are not supported in any of these options.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35992#comment:5>
Reply all
Reply to author
Forward
0 new messages