[Django] #33982: TypeError creating DB table SQL with ExclusionConstraint as Statement returned instead of str

35 views
Skip to first unread message

Django

unread,
Sep 5, 2022, 1:24:33 AM9/5/22
to django-...@googlegroups.com
#33982: TypeError creating DB table SQL with ExclusionConstraint as Statement
returned instead of str
-------------------------------------+-------------------------------------
Reporter: James | Owner: nobody
Beith |
Type: Bug | Status: new
Component: Database | Version: 4.1
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Whilst upgrading from Django 4.0.7 to 4.1 we've hit an exception
attempting to run our test suit.

We have some models with Postgres `ExclusionConstraint` constraints. When
these constraints `constraint_sql()` is called
[https://github.com/django/django/blob/4.1/django/db/backends/base/schema.py#L266
here] as part of building the test database, a `Statement`
[https://github.com/django/django/blob/4.1/django/contrib/postgres/constraints.py#L116-L127
object is returned], instead of a str, and we crash when attempting to
join them
[https://github.com/django/django/blob/4.1/django/db/backends/base/schema.py#L271-L273
here]

Looks like the `ExclusionConstraint` switched to returning a `Statement`
instead of a str in [https://github.com/django/django/pull/15235 this PR
#15235].

Stacktrace below if it helps.

{{{
../../../../.virtualenvs/acme-corp/lib/python3.8/site-
packages/pytest_django/plugin.py:465: in _django_db_marker
request.getfixturevalue("_django_db_helper")
src/tests/conftest.py:966: in django_db_setup
db_cfg = setup_databases(
../../../../.virtualenvs/acme-corp/lib/python3.8/site-
packages/django/test/utils.py:220: in setup_databases
connection.creation.create_test_db(
../../../../.virtualenvs/acme-corp/lib/python3.8/site-
packages/django/db/backends/base/creation.py:78: in create_test_db
call_command(
../../../../.virtualenvs/acme-corp/lib/python3.8/site-
packages/django/core/management/__init__.py:198: in call_command
return command.execute(*args, **defaults)
src/acme-corp/interfaces/common/management_commands.py:50: in execute
return super().execute(*args, **options)
../../../../.virtualenvs/acme-corp/lib/python3.8/site-
packages/django/core/management/base.py:448: in execute
output = self.handle(*args, **options)
src/acme-corp/interfaces/systemjobs/management/commands/migrate.py:31: in
handle
super().handle(*args, **options)
../../../../.virtualenvs/acme-corp/lib/python3.8/site-
packages/pytest_django/fixtures.py:276: in handle
return super().handle(*args, **kwargs)
../../../../.virtualenvs/acme-corp/lib/python3.8/site-
packages/django/core/management/base.py:96: in wrapped
res = handle_func(*args, **kwargs)
../../../../.virtualenvs/acme-corp/lib/python3.8/site-
packages/django/core/management/commands/migrate.py:314: in handle
self.sync_apps(connection, executor.loader.unmigrated_apps)
../../../../.virtualenvs/acme-corp/lib/python3.8/site-
packages/django/core/management/commands/migrate.py:476: in sync_apps
editor.create_model(model)
../../../../.virtualenvs/acme-corp/lib/python3.8/site-
packages/django/db/backends/base/schema.py:446: in create_model
sql, params = self.table_sql(model)
../../../../.virtualenvs/acme-corp/lib/python3.8/site-
packages/django/db/backends/base/schema.py:272: in table_sql
"definition": ", ".join(
E TypeError: sequence item 9: expected str instance, Statement found
}}}

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

Django

unread,
Sep 5, 2022, 3:02:45 AM9/5/22
to django-...@googlegroups.com
#33982: TypeError creating DB table SQL with ExclusionConstraint as Statement
returned instead of str
-------------------------------------+-------------------------------------
Reporter: James Beith | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.1
(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):

* severity: Normal => Release blocker
* stage: Unreviewed => Accepted


Comment:

Thanks for the report! Regression in
0e656c02fe945389246f0c08f51c6db4a0849bd2.

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

Django

unread,
Sep 5, 2022, 3:05:14 AM9/5/22
to django-...@googlegroups.com
#33982: TypeError creating DB table SQL with ExclusionConstraint as Statement
returned instead of str
-------------------------------------+-------------------------------------
Reporter: James Beith | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.1
(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):

* Attachment "test-33982.diff" added.

Regression test.

Django

unread,
Sep 5, 2022, 4:27:46 AM9/5/22
to django-...@googlegroups.com
#33982: TypeError creating DB table SQL with ExclusionConstraint as Statement
returned instead of str
-------------------------------------+-------------------------------------
Reporter: James Beith | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.1
(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):

James, would you like to prepare a patch?

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

Django

unread,
Sep 7, 2022, 12:36:27 AM9/7/22
to django-...@googlegroups.com
#33982: TypeError creating DB table SQL with ExclusionConstraint as Statement
returned instead of str
-------------------------------------+-------------------------------------
Reporter: James Beith | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.1
(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 James Beith):

Mariusz, how's this? Hopefully it's this straight forward.

https://github.com/django/django/pull/16035

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

Django

unread,
Sep 7, 2022, 2:24:21 AM9/7/22
to django-...@googlegroups.com
#33982: TypeError creating DB table SQL with ExclusionConstraint as Statement
returned instead of str
-------------------------------------+-------------------------------------
Reporter: James Beith | Owner: James
| Beith
Type: Bug | Status: assigned

Component: Database layer | Version: 4.1
(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):

* owner: nobody => James Beith
* status: new => assigned
* has_patch: 0 => 1
* stage: Accepted => Ready for checkin


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

Django

unread,
Sep 7, 2022, 3:17:38 AM9/7/22
to django-...@googlegroups.com
#33982: TypeError creating DB table SQL with ExclusionConstraint as Statement
returned instead of str
-------------------------------------+-------------------------------------
Reporter: James Beith | Owner: James
| Beith
Type: Bug | Status: closed

Component: Database layer | Version: 4.1
(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:"19e838daa8872ee29fbea0bc471c2a6443f26835" 19e838da]:
{{{
#!CommitTicketReference repository=""
revision="19e838daa8872ee29fbea0bc471c2a6443f26835"
Fixed #33982 -- Fixed migrations crash when adding model with
ExclusionConstraint.

Regression in 0e656c02fe945389246f0c08f51c6db4a0849bd2.
}}}

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

Django

unread,
Sep 7, 2022, 3:17:53 AM9/7/22
to django-...@googlegroups.com
#33982: TypeError creating DB table SQL with ExclusionConstraint as Statement
returned instead of str
-------------------------------------+-------------------------------------
Reporter: James Beith | Owner: James
| Beith
Type: Bug | Status: closed
Component: Database layer | Version: 4.1
(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:"7ba9a448316de976735c1b14d069ed033ebed6ea" 7ba9a448]:
{{{
#!CommitTicketReference repository=""
revision="7ba9a448316de976735c1b14d069ed033ebed6ea"
[4.1.x] Fixed #33982 -- Fixed migrations crash when adding model with
ExclusionConstraint.

Regression in 0e656c02fe945389246f0c08f51c6db4a0849bd2.

Backport of 19e838daa8872ee29fbea0bc471c2a6443f26835 from main
}}}

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

Reply all
Reply to author
Forward
0 new messages