[Django] #36813: Convert system checks for max_length and max_digits to __init__() checks.

1 view
Skip to first unread message

Django

unread,
Dec 19, 2025, 12:54:45 PM (16 hours ago) Dec 19
to django-...@googlegroups.com
#36813: Convert system checks for max_length and max_digits to __init__() checks.
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Type:
| Cleanup/optimization
Status: new | Component: Database
| layer (models, ORM)
Version: dev | 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
-------------------------------------+-------------------------------------
#28120 extended a system check validating `CharField.max_length` to also
validate that booleans are not provided.

However, system checks only check model fields, not fields constructed for
use in the `output_field` argument of an `Expression`, e.g. when using
`Cast()`. (Invalid inputs to `Cast()` error out at the db level instead of
raising nicely.)

I'm not suggesting to move ''a bunch'' of checks over to
`*Field.__init__()`, but I ''am'' suggesting that for simple checks on
`isinstance` and `> 0` that we could error out in
`{Char,Decimal}Field.__init__` instead of via a system check, to catch
additional usage mistakes.

Another use case besides `output_field` would be for database setup before
tests run checks, as in #34727.
--
Ticket URL: <https://code.djangoproject.com/ticket/36813>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 19, 2025, 2:27:43 PM (15 hours ago) Dec 19
to django-...@googlegroups.com
#36813: Convert system checks for max_length and max_digits to __init__() checks.
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Mehraz
Type: | Hossain Rumman
Cleanup/optimization | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
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
-------------------------------------+-------------------------------------
Changes (by Mehraz Hossain Rumman):

* cc: Mehraz Hossain Rumman (added)
* owner: (none) => Mehraz Hossain Rumman
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/36813#comment:1>
Reply all
Reply to author
Forward
0 new messages