[Django] #35815: System check for default database values with expressions prohibits non-expressions

23 views
Skip to first unread message

Django

unread,
Oct 4, 2024, 9:37:33 AM10/4/24
to django-...@googlegroups.com
#35815: System check for default database values with expressions prohibits non-
expressions
-------------------------------------+-------------------------------------
Reporter: Tim Graham | Type: Bug
Status: new | Component: Core
| (System checks)
Version: 5.0 | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Since its introduction in Django 5.0,
[https://github.com/django/django/blob/c334c1a8ff4579cdb1dd77cce8da747070ac9fc4/django/db/models/fields/__init__.py#L411-L420
the fields.E011 system check] for database backends that have
`DatabaseFeatures.supports_expression_defaults = False`
[https://github.com/django/django/blob/c334c1a8ff4579cdb1dd77cce8da747070ac9fc4/django/db/models/fields/__init__.py#L393-L398
requires literal defaults to be wrapped in Value].

There are a number of test models that have
[https://github.com/django/django/blob/c334c1a8ff4579cdb1dd77cce8da747070ac9fc4/tests/field_defaults/models.py#L46-L47
int, float] and
[https://github.com/django/django/blob/c334c1a8ff4579cdb1dd77cce8da747070ac9fc4/tests/field_defaults/models.py#L64
string] db_defaults that will raise a system check error if
`DatabaseFeatures.supports_expression_defaults = False`
since these models don't have `required_db_features =
{"supports_expression_defaults"}`.

I'm working on MongoDB which doesn't support any database defaults,
literal or expressions.
--
Ticket URL: <https://code.djangoproject.com/ticket/35815>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 4, 2024, 9:37:53 AM10/4/24
to django-...@googlegroups.com
#35815: System check for default database values with expressions prohibits non-
expressions
-------------------------------------+-------------------------------------
Reporter: Tim Graham | Owner: (none)
Type: Bug | Status: new
Component: Core (System | Version: 5.0
checks) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Tim Graham):

I'm not sure if the appropriate solution is to add `Value` wrapping to all
literal defaults in Django's test models or to modify the
[https://github.com/django/django/blob/c334c1a8ff4579cdb1dd77cce8da747070ac9fc4/django/db/models/fields/__init__.py#L395
isinstance(db_default, Value)] check to also accept int/float, str, etc.
--
Ticket URL: <https://code.djangoproject.com/ticket/35815#comment:1>

Django

unread,
Oct 7, 2024, 3:30:22 AM10/7/24
to django-...@googlegroups.com
#35815: System check for default database values with expressions prohibits non-
expressions
--------------------------------------+------------------------------------
Reporter: Tim Graham | Owner: (none)
Type: Bug | Status: new
Component: Core (System checks) | Version: 5.0
Severity: Normal | 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):

* cc: Lily Foote (added)
* stage: Unreviewed => Accepted

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

Django

unread,
Oct 7, 2024, 4:34:03 AM10/7/24
to django-...@googlegroups.com
#35815: System check for default database values with expressions prohibits non-
expressions
--------------------------------------+------------------------------------
Reporter: Tim Graham | Owner: (none)
Type: Bug | Status: new
Component: Core (System checks) | Version: 5.0
Severity: Normal | 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 Lily Foote):

I think either solution could work, but maybe there's a subtlety I don't
remember. I think wrapping all literals in `Value` is most likely to just
work.
--
Ticket URL: <https://code.djangoproject.com/ticket/35815#comment:3>

Django

unread,
Oct 8, 2024, 9:27:37 AM10/8/24
to django-...@googlegroups.com
#35815: System check for default database values with expressions prohibits non-
expressions
--------------------------------------+------------------------------------
Reporter: Tim Graham | Owner: (none)
Type: Bug | Status: new
Component: Core (System checks) | Version: 5.0
Severity: Normal | 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 Tim Graham):

The issue I see with requiring `Value` wrapping is that third-party apps
may not know to do it and therefore run into compatibility issues with
backends with `supports_expression_defaults = False`.​ For the other
solution I suggested, I'm not sure we can make the `isinstance()`check
exhaustive for all possible non-expression types.

Perhaps it's more appropriate to replace `isinstance(self.db_default,
Value)` with `not hasattr(self.db_default, "resolve_expression")` to
reject expressions.
--
Ticket URL: <https://code.djangoproject.com/ticket/35815#comment:4>

Django

unread,
Nov 11, 2024, 8:32:11 AM11/11/24
to django-...@googlegroups.com
#35815: System check for default database values with expressions prohibits non-
expressions
--------------------------------------+------------------------------------
Reporter: Tim Graham | Owner: (none)
Type: Bug | Status: new
Component: Core (System checks) | Version: 5.0
Severity: Normal | 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 Tim Graham):

* has_patch: 0 => 1

Comment:

[https://github.com/django/django/pull/18795 PR] to prevent the system
check from rejecting `Field.db_default` literals (integer, float, boolean,
etc.) when `DatabaseFeatures.supports_expression_defaults = False`.
--
Ticket URL: <https://code.djangoproject.com/ticket/35815#comment:5>

Django

unread,
Nov 11, 2024, 9:16:48 AM11/11/24
to django-...@googlegroups.com
#35815: System check for default database values with expressions prohibits non-
expressions
-------------------------------------+-------------------------------------
Reporter: Tim Graham | Owner: Tim
| Graham
Type: Bug | Status: assigned
Component: Core (System | Version: 5.0
checks) |
Severity: Normal | 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 Sarah Boyce):

* owner: (none) => Tim Graham
* status: new => assigned

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

Django

unread,
Nov 11, 2024, 10:02:38 AM11/11/24
to django-...@googlegroups.com
#35815: System check for default database values with expressions prohibits non-
expressions
-------------------------------------+-------------------------------------
Reporter: Tim Graham | Owner: Tim
| Graham
Type: Bug | Status: assigned
Component: Core (System | Version: 5.0
checks) |
Severity: Normal | 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/35815#comment:7>

Django

unread,
Nov 11, 2024, 10:05:24 AM11/11/24
to django-...@googlegroups.com
#35815: System check for default database values with expressions prohibits non-
expressions
-------------------------------------+-------------------------------------
Reporter: Tim Graham | Owner: Tim
| Graham
Type: Bug | Status: closed
Component: Core (System | Version: 5.0
checks) |
Severity: Normal | 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:"c4614b53d355561d426b0fed903e96c3c198e10d" c4614b5]:
{{{#!CommitTicketReference repository=""
revision="c4614b53d355561d426b0fed903e96c3c198e10d"
Fixed #35815 -- Made system check accept db_default literals when
DatabaseFeatures.supports_expression_defaults = False.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35815#comment:8>
Reply all
Reply to author
Forward
0 new messages