[Django] #34936: db_default with decimal.Decimal() crashes on SQLite.

24 views
Skip to first unread message

Django

unread,
Oct 30, 2023, 5:04:25 AM10/30/23
to django-...@googlegroups.com
#34936: db_default with decimal.Decimal() crashes on SQLite.
-------------------------------------+-------------------------------------
Reporter: Mariusz | Owner: nobody
Felisiak |
Type: Bug | Status: new
Component: Database | Version: 5.0
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 |
-------------------------------------+-------------------------------------
`db_default` with `decimal.Decimal()` crashes on SQLite. For example,
adding the following field
{{{#!python
models.DecimalField(null=True, max_digits=5, decimal_places=2,
db_default=Decimal("3.33")
}}}
generates:
{{{#!sql
ALTER TABLE "test_adfldd_pony" ADD COLUMN "height" decimal DEFAULT
CAST('3.33' AS NUMERIC) NULL;
}}}
and crashes with:
{{{
django.db.utils.OperationalError: near "(": syntax error
}}}

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

Django

unread,
Oct 30, 2023, 5:29:55 AM10/30/23
to django-...@googlegroups.com
#34936: db_default with decimal.Decimal() crashes on SQLite.
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | 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 David Sanders):

* stage: Unreviewed => Accepted


Comment:

Confirmed that SQLite doesn't like `CAST(…)` in the `DEFAULT` clause
unless wrapped in parens 👍

https://www.sqlite.org/lang_createtable.html#the_default_clause

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

Django

unread,
Oct 30, 2023, 5:48:27 AM10/30/23
to django-...@googlegroups.com
#34936: db_default with decimal.Decimal() crashes on SQLite.
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: David
| Sanders
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 David Sanders):

* owner: nobody => David Sanders
* status: new => assigned
* has_patch: 0 => 1


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

Django

unread,
Nov 2, 2023, 12:30:22 PM11/2/23
to django-...@googlegroups.com
#34936: db_default with decimal.Decimal() crashes on SQLite.
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: David
| Sanders
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/34936#comment:3>

Django

unread,
Nov 2, 2023, 2:59:36 PM11/2/23
to django-...@googlegroups.com
#34936: db_default with decimal.Decimal() crashes on SQLite.
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: David
| Sanders
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:"797957fb48f63760442d3d4c8985fd94f8602d5e" 797957fb]:
{{{
#!CommitTicketReference repository=""
revision="797957fb48f63760442d3d4c8985fd94f8602d5e"
Fixed #34936 -- Fixed migration crash for DecimalField with db_default on
SQLite.

CAST() must be wrapped in parentheses to be recognized as an expression on
SQLite.

Regression in 7414704e88d73dafbcfbb85f9bc54cb6111439d3.
}}}

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

Django

unread,
Nov 2, 2023, 2:59:36 PM11/2/23
to django-...@googlegroups.com
#34936: db_default with decimal.Decimal() crashes on SQLite.
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: David
| Sanders
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
-------------------------------------+-------------------------------------

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

In [changeset:"1944f490f91e44e1378d53420b64a78163aea815" 1944f49]:
{{{
#!CommitTicketReference repository=""
revision="1944f490f91e44e1378d53420b64a78163aea815"
Refs #34936 -- Added test for altering DecimalField with db_default to
non-nullable.
}}}

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

Django

unread,
Nov 2, 2023, 3:00:00 PM11/2/23
to django-...@googlegroups.com
#34936: db_default with decimal.Decimal() crashes on SQLite.
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: David
| Sanders
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:"8dde0504f3771ff2707bdddb702eaf5c06bb77a7" 8dde0504]:
{{{
#!CommitTicketReference repository=""
revision="8dde0504f3771ff2707bdddb702eaf5c06bb77a7"
[5.0.x] Fixed #34936 -- Fixed migration crash for DecimalField with
db_default on SQLite.

CAST() must be wrapped in parentheses to be recognized as an expression on
SQLite.

Regression in 7414704e88d73dafbcfbb85f9bc54cb6111439d3.

Backport of 797957fb48f63760442d3d4c8985fd94f8602d5e from main
}}}

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

Django

unread,
Feb 1, 2024, 2:13:51 AM2/1/24
to django-...@googlegroups.com
#34936: db_default with decimal.Decimal() crashes on SQLite.
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: David
| Sanders
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:"06b05c748ff4079411b7e570311de879671399df" 06b05c7]:
{{{#!CommitTicketReference repository=""
revision="06b05c748ff4079411b7e570311de879671399df"
[5.0.x] Refs #34936 -- Added test for altering DecimalField with
db_default to non-nullable.

Backport of 1944f490f91e44e1378d53420b64a78163aea815 from main
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34936#comment:7>

Reply all
Reply to author
Forward
0 new messages