[Django] #35759: Don't require max_length on CharField on SQLite backend

17 views
Skip to first unread message

Django

unread,
Sep 12, 2024, 10:20:33 PM9/12/24
to django-...@googlegroups.com
#35759: Don't require max_length on CharField on SQLite backend
-------------------------------------+-------------------------------------
Reporter: Curtis Maloney | Type: New
| feature
Status: new | Component: Database
| layer (models, ORM)
Version: 5.0 | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Some trivial testing suggests that SQLite doesn't require a length on
VARCHAR / TEXT fields, just like Postgres.
--
Ticket URL: <https://code.djangoproject.com/ticket/35759>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 12, 2024, 10:22:07 PM9/12/24
to django-...@googlegroups.com
#35759: Don't require max_length on CharField on SQLite backend
-------------------------------------+-------------------------------------
Reporter: Curtis Maloney | Owner: (none)
Type: New feature | Status: new
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Curtis Maloney):

It would vastly simplify my own package testing if I didn't have to spin
up a PG instance for models written assuming I can omit `max_length`, and
could instead use a disposable SQLite DB.
--
Ticket URL: <https://code.djangoproject.com/ticket/35759#comment:1>

Django

unread,
Sep 12, 2024, 11:50:24 PM9/12/24
to django-...@googlegroups.com
#35759: Don't require max_length on CharField on SQLite backend
-------------------------------------+-------------------------------------
Reporter: Curtis Maloney | Owner: (none)
Type: New feature | Status: new
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* stage: Unreviewed => Accepted

Comment:

SQLite doesn't enforce any database constraints when a max length is
specified (see #21471 and [https://forum.djangoproject.com/t/idea-make-
sqlite-enforce-varchar-lengths-via-check-constraints/33101 this recent
forum discussion on the subject]) so supporting `max_length=None` on
SQLite is trivial (we already implicitly do).

For anyone interested in picking this up the patch needs three things

1. The SQLite backend's `supports_unlimited_charfield` feature flag must
be set to true.
2. The `CharField`documentation must be adjusted to mention
[https://github.com/django/django/blob/16af0c60ed90813ed70ecef4e64a89301ed0f0a2/docs/ref/models/fields.txt#L723
the feature is available of SQLite as well] with a `::versionchanged`.
3. A release note must be added.
--
Ticket URL: <https://code.djangoproject.com/ticket/35759#comment:2>

Django

unread,
Sep 13, 2024, 12:37:12 AM9/13/24
to django-...@googlegroups.com
#35759: Don't require max_length on CharField on SQLite backend
-------------------------------------+-------------------------------------
Reporter: Curtis Maloney | Owner: (none)
Type: New feature | Status: new
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jae Hyuck Sa ):

I’ve always been interested in Database/ORM, so I’d like to handle this
ticket myself. Thank you, Simon Charette, for providing such detailed
guidelines.
--
Ticket URL: <https://code.djangoproject.com/ticket/35759#comment:3>

Django

unread,
Sep 13, 2024, 12:37:18 AM9/13/24
to django-...@googlegroups.com
#35759: Don't require max_length on CharField on SQLite backend
-------------------------------------+-------------------------------------
Reporter: Curtis Maloney | Owner: Jae Hyuck
| Sa
Type: New feature | Status: assigned
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jae Hyuck Sa ):

* owner: (none) => Jae Hyuck Sa
* status: new => assigned

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

Django

unread,
Sep 13, 2024, 7:13:19 AM9/13/24
to django-...@googlegroups.com
#35759: Don't require max_length on CharField on SQLite backend
-------------------------------------+-------------------------------------
Reporter: Curtis Maloney | Owner: Jae Hyuck
| Sa
Type: New feature | Status: assigned
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jae Hyuck Sa ):

* has_patch: 0 => 1

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

Django

unread,
Sep 13, 2024, 10:27:59 AM9/13/24
to django-...@googlegroups.com
#35759: Don't require max_length on CharField on SQLite backend
-------------------------------------+-------------------------------------
Reporter: Curtis Maloney | Owner: Jae Hyuck
| Sa
Type: New feature | Status: assigned
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):

Patch is looking great.

For the record #34887 initially rejected this feature but I think it
warrants being revisited. The argument provided by Mariusz at the time was

> We accepted #14094, because CharField and TextField use different
datatypes on PostgreSQL.

but in the end both `varchar` and `text`
[https://www.depesz.com/2010/03/02/charx-vs-varcharx-vs-varchar-vs-text/
are aliases for the internal Postgres] `varlena` type so I don't think the
argument stands. There are reason why we'd want to allow
`CharField(max_length=None)` on
[https://code.djangoproject.com/ticket/14094#comment:5 all backends that
allow it] which #14094 does a good job at covering.
--
Ticket URL: <https://code.djangoproject.com/ticket/35759#comment:6>

Django

unread,
Sep 13, 2024, 12:47:33 PM9/13/24
to django-...@googlegroups.com
#35759: Don't require max_length on CharField on SQLite backend
-------------------------------------+-------------------------------------
Reporter: Curtis Maloney | Owner: Jae Hyuck
| Sa
Type: New feature | Status: assigned
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jae Hyuck Sa ):

Replying to [comment:6 Simon Charette]:
> Patch is looking great.
>
> For the record #34887 initially rejected this feature but I think it
warrants being revisited. The argument provided by Mariusz at the time was
>
> > We accepted #14094, because CharField and TextField use different
datatypes on PostgreSQL.
>
> but in the end both `varchar` and `text`
[https://www.depesz.com/2010/03/02/charx-vs-varcharx-vs-varchar-vs-text/
are aliases for the internal Postgres] `varlena` type so I don't think the
argument stands. There are reason why we'd want to allow
`CharField(max_length=None)` on
[https://code.djangoproject.com/ticket/14094#comment:5 all backends that
allow it] which #14094 does a good job at covering.

Thank you for the detailed explanation! :)
>
> Moreover the addition of this feature could allow us to eventually
automatically add a check constraint for `max_length` on SQLite by
allowing users to disable it entirely by setting the value to `None`.
--
Ticket URL: <https://code.djangoproject.com/ticket/35759#comment:7>

Django

unread,
Sep 14, 2024, 5:00:33 PM9/14/24
to django-...@googlegroups.com
#35759: Don't require max_length on CharField on SQLite backend
-------------------------------------+-------------------------------------
Reporter: Curtis Maloney | Owner: Jae Hyuck
| Sa
Type: New feature | Status: assigned
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Mariusz Felisiak):

If we want to accept this, #35759 should be closed as a duplicate of
#34887, and eventually #34887 reopened.
--
Ticket URL: <https://code.djangoproject.com/ticket/35759#comment:8>

Django

unread,
Sep 16, 2024, 4:47:57 AM9/16/24
to django-...@googlegroups.com
#35759: Don't require max_length on CharField on SQLite backend
-------------------------------------+-------------------------------------
Reporter: Curtis Maloney | Owner: Jae Hyuck
| Sa
Type: New feature | Status: closed
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* resolution: => duplicate
* status: assigned => closed

Comment:

Duplicate of #34887
--
Ticket URL: <https://code.djangoproject.com/ticket/35759#comment:9>
Reply all
Reply to author
Forward
0 new messages