#36886: URLField max_length cannot take advantage of 
supports_unlimited_charfield
in DB backend
-------------------------------------+-------------------------------------
               Reporter:  Joel D     |          Owner:  Joel D Sleppy
  Sleppy                             |
                   Type:             |         Status:  assigned
  Uncategorized                      |
              Component:  Database   |        Version:  6.0
  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          |
-------------------------------------+-------------------------------------
 When using a DB backend that `supports_unlimited_charfield` (postgres,
 sqlite), a `CharField` can omit `max_length` and allow arbitrarily long
 values in the database.  However `URLField`, which inherits from
 `CharField`, forces the developer to pick a maximum length.  For example,
 this model class:

 {{{#!python
 class Thing(models.Model):
     chars = models.CharField()
     url = models.URLField()
 }}}

 Creates this table in postgres:

 {{{
                                  Table "public.app_thing"
  Column |          Type          | Collation | Nullable |
 Default
 
--------+------------------------+-----------+----------+----------------------------------
  id     | bigint                 |           | not null | generated by
 default as identity
  chars  | character varying      |           | not null |
  url    | character varying(200) |           | not null |
 }}}

 And trying to set `url = models.URLField(max_length=None)` does not get
 recognized as a change by `makemigrations`.

 URLs can get quite long and it's an inconvenience to pick a maximum length
 (and to defensively code against the possibility of it being violated).
 I'd like to work on this improvement myself if there's any appetite for
 it.

 Possible changes:

 - For backwards compatibility, continue to default `max_length` to `200`
 but allow specifying `None` to have an unbounded field.
 - Break backwards compatibility, changing behavior to match that of
 `CharField`.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36886>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019bfb35b5ca-9a51c09f-5a65-47a4-9a4f-4bb18897972d-000000%40eu-central-1.amazonses.com.

Reply via email to