#22739: CharField for Forms raises on empty string
-------------------------+--------------------------------------
Reporter: jeremyt | Owner: nobody
Type: Bug | Status: closed
Component: Forms | Version: 1.6
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------+--------------------------------------
Changes (by erikr):
* status: new => closed
* needs_docs: => 0
* resolution: => wontfix
* needs_tests: => 0
* needs_better_patch: => 0
Comment:
I can see your point, but the required check has been specifically written
to fail on an empty string as if it had been missing. Each field defines a
set of `empty_values`, with the default
[https://github.com/django/django/blob/master/django/core/validators.py#L15|
including an empty string]. If the value is in `empty_values`, this
[https://github.com/django/django/blob/master/django/forms/fields.py#L129|
triggers the required error].
I don't really see a way to change this behaviour in Django without
causing numerous other issues. However, a simple workaround would probably
be for you to make your own subclass of `forms.CharField`, in which you
override the `empty_values` attribute to only include `None`. You can then
use that to only get the `ValidationError` when the value was absent
instead of empty. This is not a public API as far as I can find, so it
might change in the future.
Closing as wontfix, but please reopen if you disagree.
--
Ticket URL: <https://code.djangoproject.com/ticket/22739#comment:1>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.b4e880e0904217912ca0a575ad8505ca%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.