[Django] #35997: Migrations crash on constraints/indexes with CompositePrimaryKey in fields.

10 views
Skip to first unread message

Django

unread,
Dec 10, 2024, 3:43:16 PM12/10/24
to django-...@googlegroups.com
#35997: Migrations crash on constraints/indexes with CompositePrimaryKey in fields.
-------------------------------------+-------------------------------------
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` in `fields`. Unfortunately, it crashes when trying
to migrate:
{{{
...
File "/django/db/backends/base/schema.py", line 509, in create_model
sql, params = self.table_sql(model)
^^^^^^^^^^^^^^^^^^^^^
File "/django/db/backends/base/schema.py", line 283, in table_sql
constraint_sqls.extend(
File "/django/db/backends/base/schema.py", line 284, in <genexpr>
constraint.constraint_sql(model, self)
File "/django/db/models/constraints.py", line 512, in constraint_sql
return schema_editor._unique_sql(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/django/db/backends/base/schema.py", line 1839, in _unique_sql
"columns": ", ".join([self.quote_name(field.column) for field in
fields]),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/django/db/backends/base/schema.py", line 207, in quote_name
return self.connection.ops.quote_name(name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/django/db/backends/postgresql/operations.py", line 190, in
quote_name
if name.startswith('"') and name.endswith('"'):
^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'startswith'

}}}

It's similar to the #35992 but fix is in a completely different place so I
decided to create a separate ticket.

Bug in 978aae4334fa71ba78a3e94408f0f3aebde8d07c
--
Ticket URL: <https://code.djangoproject.com/ticket/35997>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 10, 2024, 3:55:46 PM12/10/24
to django-...@googlegroups.com
#35997: Migrations crash on constraints/indexes with CompositePrimaryKey in fields.
-------------------------------------+-------------------------------------
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 Natalia Bidart):

* stage: Unreviewed => Accepted

Comment:

Thank you Mariusz!!!
--
Ticket URL: <https://code.djangoproject.com/ticket/35997#comment:1>

Django

unread,
Dec 11, 2024, 3:57:57 PM12/11/24
to django-...@googlegroups.com
#35997: Migrations crash on constraints/indexes with CompositePrimaryKey in fields.
-------------------------------------+-------------------------------------
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/18922 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/35997#comment:2>

Django

unread,
Dec 17, 2024, 4:28:16 AM12/17/24
to django-...@googlegroups.com
#35997: Migrations crash on constraints/indexes with CompositePrimaryKey in fields.
-------------------------------------+-------------------------------------
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/35997#comment:3>

Django

unread,
Dec 17, 2024, 4:28:49 AM12/17/24
to django-...@googlegroups.com
#35997: Migrations crash on constraints/indexes with CompositePrimaryKey in fields.
-------------------------------------+-------------------------------------
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/35997#comment:4>
Reply all
Reply to author
Forward
0 new messages