Opened 4 years ago

Closed 4 years ago

#31063 closed Bug (duplicate)

Make URL validators consistent.

Reported by: Alexandre Sapet Owned by: nobody
Component: Core (Other) Version: dev
Severity: Normal Keywords: url validator
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no



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.

Change History (1)

comment:1 by Mariusz Felisiak, 4 years ago

Component: contrib.adminCore (Other)
Resolution: duplicate
Status: newclosed
Summary: Make URL validators consistent between django/core/validators.URLValidator (for admin) django/db/models/fields.URLField (urllib)Make URL validators consistent.
Version: 2.2master

In both cases Django uses the same validator django.core.validators.URLValidator. Note that doesn't validate fields (see documentation). You can subclass URLField and add s3 to the list of accepted schemas, e.g.

class MyURLField(URLField):
    default_validators = [validators.URLValidator(schemes=['s3', 'http', 'https', 'ftp', 'ftps'])]

Solving #25594 should make it easier.

Duplicate of #26418.

Note: See TracTickets for help on using tickets.
Back to Top