[Django] #31063: Make URL validators consistent between django/core/validators.URLValidator (for admin) django/db/models/fields.URLField (urllib)

60 views
Skip to first unread message

Django

unread,
Dec 4, 2019, 11:09:55 AM12/4/19
to django-...@googlegroups.com
#31063: Make URL validators consistent between django/core/validators.URLValidator
(for admin) django/db/models/fields.URLField (urllib)
-----------------------------------------+-------------------------------
Reporter: AlexandreSi | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 2.2
Severity: Normal | Keywords: url validator
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+-------------------------------
Hi,

I am currently using an URLField to store an AWS S3 URL for one of my
models (`s3://bucket/prefix`).

URLField uses urllib to validate the URL and finds this URL consistent;
but the URL validator used by Django Admin is different and demands that
the scheme of the URL must be one of `schemes = ['http', 'https', 'ftp',
'ftps']`.

The effect is that you can't modify an instance on Django Admin because it
blocks saving.

The bug is in Django 2.2 and 3.0.

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

Django

unread,
Dec 5, 2019, 2:34:15 AM12/5/19
to django-...@googlegroups.com
#31063: Make URL validators consistent.
-------------------------------+--------------------------------------
Reporter: AlexandreSi | Owner: nobody
Type: Bug | Status: closed
Component: Core (Other) | Version: master
Severity: Normal | Resolution: duplicate

Keywords: url validator | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by felixxm):

* status: new => closed
* component: contrib.admin => Core (Other)
* version: 2.2 => master
* resolution: => duplicate


Comment:

In both cases Django uses the same validator
`django.core.validators.URLValidator`. Note that `Model.save()` doesn't
validate fields (see
[https://docs.djangoproject.com/en/3.0/ref/models/instances/#what-happens-
when-you-save documentation]). You can subclass `URLField` and add `s3` to
the list of accepted schemas, e.g.
{{{#!python
class MyURLField(URLField):
default_validators = [validators.URLValidator(schemes=['s3', 'http',
'https', 'ftp', 'ftps'])]
}}}

Solving #25594 should make it easier.

Duplicate of #26418.

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

Reply all
Reply to author
Forward
0 new messages