[Django] #32954: Improve error message with URLValidator and schemes

3 views
Skip to first unread message

Django

unread,
Jul 20, 2021, 7:28:51 PM7/20/21
to django-...@googlegroups.com
#32954: Improve error message with URLValidator and schemes
-------------------------------------+-------------------------------------
Reporter: tomdjango | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: | Version: 3.2
Uncategorized |
Severity: Normal | Keywords: error message
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
If you limit the schemes for a URL to a subset of legal values with
URLValidator, like this:

url = models.URLField(max_length=200,
validators=[URLValidator(["http","https"])])

And then enter a value URL starting with "ftp://", the error message given
is

Enter a valid URL.

The URL is valid, so this does not give the user useful information for
fixing the problem. Something like

URL must begin with one of [http, https]

would be more helpful.

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

Django

unread,
Jul 21, 2021, 5:52:18 AM7/21/21
to django-...@googlegroups.com
#32954: Improve error message with URLValidator and schemes
-------------------------------------+-------------------------------------
Reporter: tomdjango | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Uncategorized | Version: 3.2
Severity: Normal | Resolution: wontfix

Keywords: error message | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* status: new => closed
* resolution: => wontfix


Comment:

I think using [https://docs.djangoproject.com/en/3.2/ref/models/fields
/#error-messages `error_messages`] is the way forward here.

I don't think we can change the default — too many projects will depend on
that — and I'd guess folks would object that we were leaking unwanted info
if we added extra context here.

What's a Valid URL for the application depends on the validators in play.
Lots and lots and lots of "Valid URLs" (from an RFC perspective) are
already excluded by `URLValidator.schemes`' default value. "Enter a valid
URL." already takes this into account.

I hope that makes sense.

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

Reply all
Reply to author
Forward
0 new messages