Re: [Django] #35880: Form Field.requried docs invalid example due to CharField.strip

15 views
Skip to first unread message

Django

unread,
Nov 4, 2024, 3:01:04 AM11/4/24
to django-...@googlegroups.com
#35880: Form Field.requried docs invalid example due to CharField.strip
--------------------------------------+------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: Bug | Status: assigned
Component: Documentation | Version: 5.1
Severity: Normal | Resolution:
Keywords: Form Fields Document | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Description changed by Sarah Boyce:

Old description:

> Hello!
> I created an issue by finded the wrong parts and the good parts when
> improved in the Form fields document.
>
> 1.
> [https://docs.djangoproject.com/en/5.1/ref/forms/fields/#django.forms.Field.required
> Field.requried section ] invalid example.
>
> {{{
> >>> from django import forms
> >>> f = forms.CharField()
> ...
> >> f.clean(" ")
> ' '
> }}}
> In the example passed a character string with spaces as a factor in the
> clean method to a CharField instance.
> This part is cleared space by CharField's to_python method, result is an
> empty_value so occur validation error.
> {{{
> class CharField(Field):
> ...
> def to_python(self, value):
> """Return a string."""
> if value not in self.empty_values:
> value = str(value)
> if self.strip:
> value = value.strip() # before value: " ", after value:
> ""
> if value in self.empty_values:
> return self.empty_value
> return value
> ...
> }}}
> However, in the current document, a string containing spaces seems to
> pass through the clean method.
>
> ----
>
> ~~2.
> [https://docs.djangoproject.com/en/5.1/ref/forms/fields/#django.forms.Field.label
> Field.label section] unclear part -> ("outputting forms as HTML" above)~~
>
> ~~It is unclear what " 'Outputting forms as HTML' above" refers to in the
> Field label section.
> This part probably means the
> [https://docs.djangoproject.com/en/5.1/ref/forms/api/#outputting-forms-
> as-html "Outputting forms as HTML" section] of the Forms API Document.~~
>
> ----
>
> ~~3. Consistency "fallback" and link message~~
>
> ~~This part is very trivial :)~~
>
> ~~The word "fallback" used in the
> [https://docs.djangoproject.com/en/5.1/ref/forms/fields/#django.forms.Field.initial
> field initial section] are two values "fallback" and "fall back".~~
> ~~{{{
> "Also note that initial values are not used as "fallback" ...
> ---
> >>> f.is_valid()
> False
> # The form does *not* fall back to using ....
> ...
> }}}~~
>
> ~~I think it would be better to include documentation in the message set
> as a link.~~
> ~~(Like the link message used in
> [https://docs.djangoproject.com/en/5.1/ref/forms/fields/#validators
> validators section].)~~
> ~~{{{
>
> ``localize``
> ------------
>
> .. attribute:: Field.localize
>
> The ``localize`` argument enables the localization of form data input, as
> well
> as the rendered output.
>
> See the :doc:`format localization </topics/i18n/formatting>`
> documentation for # --> See the :doc:`format localization
> documentation</topics/i18n/formatting> ` for more information.
> }}}~~

New description:

Hello!
I created an issue by finded the wrong parts and the good parts when
improved in the Form fields document.

1.
[https://docs.djangoproject.com/en/5.1/ref/forms/fields/#django.forms.Field.required
Field.requried section ] invalid example.

{{{
>>> from django import forms
>>> f = forms.CharField()
...
>> f.clean(" ")
' '
}}}
In the example passed a character string with spaces as a factor in the
clean method to a CharField instance.
This part is cleared space by CharField's to_python method, result is an
empty_value so occur validation error.
{{{
class CharField(Field):
...
def to_python(self, value):
"""Return a string."""
if value not in self.empty_values:
value = str(value)
if self.strip:
value = value.strip() # before value: " ", after value:
""
if value in self.empty_values:
return self.empty_value
return value
...
}}}
However, in the current document, a string containing spaces seems to pass
through the clean method.

----

~~2.
[https://docs.djangoproject.com/en/5.1/ref/forms/fields/#django.forms.Field.label
Field.label section] unclear part -> ("outputting forms as HTML" above)~~

~~It is unclear what " 'Outputting forms as HTML' above" refers to in the
Field label section.
This part probably means the
[https://docs.djangoproject.com/en/5.1/ref/forms/api/#outputting-forms-as-
html "Outputting forms as HTML" section] of the Forms API Document.~~

----

~~3. Consistency "fallback" and link message~~

~~This part is very trivial :)~~

~~The word "fallback" used in the
[https://docs.djangoproject.com/en/5.1/ref/forms/fields/#django.forms.Field.initial
field initial section] are two values "fallback" and "fall back".~~
{{{
"Also note that initial values are not used as "fallback" ...
---
>>> f.is_valid()
False
# The form does *not* fall back to using ....
...
}}}

~~I think it would be better to include documentation in the message set
as a link.~~
~~(Like the link message used in
[https://docs.djangoproject.com/en/5.1/ref/forms/fields/#validators
validators section].)~~
{{{

``localize``
------------

.. attribute:: Field.localize

The ``localize`` argument enables the localization of form data input, as
well
as the rendered output.

See the :doc:`format localization </topics/i18n/formatting>` documentation
for # --> See the :doc:`format localization
documentation</topics/i18n/formatting> ` for more information.
}}}

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

Django

unread,
Nov 4, 2024, 3:02:15 AM11/4/24
to django-...@googlegroups.com
#35880: Form Field.requried docs invalid example due to CharField.strip
--------------------------------------+------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: Bug | Status: assigned
Component: Documentation | Version: 5.1
Severity: Normal | Resolution:
Keywords: Form Fields Document | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by Sarah Boyce):

2 and 3 can be done without a ticket, 1 is an issue here which I have
added a comment on your patch
--
Ticket URL: <https://code.djangoproject.com/ticket/35880#comment:7>

Django

unread,
Nov 4, 2024, 3:12:55 AM11/4/24
to django-...@googlegroups.com
#35880: Form Field.requried docs invalid example due to CharField.strip
--------------------------------------+------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: Bug | Status: assigned
Component: Documentation | Version: 5.1
Severity: Normal | Resolution:
Keywords: Form Fields Document | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/35880#comment:8>

Django

unread,
Nov 4, 2024, 6:01:33 PM11/4/24
to django-...@googlegroups.com
#35880: Form Field.requried docs invalid example due to CharField.strip
--------------------------------------+------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: Bug | Status: assigned
Component: Documentation | Version: 5.1
Severity: Normal | Resolution:
Keywords: Form Fields Document | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Antoliny):

* needs_better_patch: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/35880#comment:9>

Django

unread,
Nov 5, 2024, 3:55:19 AM11/5/24
to django-...@googlegroups.com
#35880: Form Field.requried docs invalid example due to CharField.strip
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: Bug | Status: assigned
Component: Documentation | Version: 5.1
Severity: Normal | Resolution:
Keywords: Form Fields | Triage Stage: Ready for
Document | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/35880#comment:10>

Django

unread,
Nov 5, 2024, 9:37:16 AM11/5/24
to django-...@googlegroups.com
#35880: Form Field.requried docs invalid example due to CharField.strip
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: Bug | Status: closed
Component: Documentation | Version: 5.1
Severity: Normal | Resolution: fixed
Keywords: Form Fields | Triage Stage: Ready for
Document | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce <42296566+sarahboyce@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"cae0c7f48ae1257963e76988ff2d5897ffc40ccb" cae0c7f4]:
{{{#!CommitTicketReference repository=""
revision="cae0c7f48ae1257963e76988ff2d5897ffc40ccb"
[5.1.x] Fixed #35880 -- Removed invalid example in form Field.required
docs due to CharField.strip.

CharField.strip was introduced in
11cac1bd8ef7546ca32d9969d4348bf412dc6664, and is True by
default, meaning the previous example of " " raised a ValidationError.

Backport of 72de38239fdc97751e1e4ed245c7073c31bbd28a from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35880#comment:11>
Reply all
Reply to author
Forward
0 new messages