[Django] #33864: Deprecate length_is template filter in favor of length.

42 views
Skip to first unread message

Django

unread,
Jul 22, 2022, 6:01:21 PM7/22/22
to django-...@googlegroups.com
#33864: Deprecate length_is template filter in favor of length.
-------------------------------------+-------------------------------------
Reporter: Nick Pope | Owner: Nick Pope
Type: | Status: assigned
Cleanup/optimization |
Component: Template | Version: dev
system | Keywords: length_is, length,
Severity: Normal | template, filter
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
The `length_is` template filter is a vestige from the days of the `{%
ifequal %}` and `{% ifnotequal %}` days before `{% if %}` arrived with
support for comparison with operators. Even the example in the
documentation (see
[https://docs.djangoproject.com/en/4.0/ref/templates/builtins/#length-is
here]) is poor: `{{ value|length_is:"4" }}` will only return one of three
possible values - `True`, `False`, or `""`, the empty string being for
errors in the provided values.

It seems to me that it would be better to encourage use of the `length`
template filter with the `{% if %}` template tag which can provide more
flexibility:

{{{#!django
{# Before: #}
{% if value|length_is:"4" %}...{% endif %}
{{ value|length_is:"4" }} ← This is of dubious use given the restricted
set of possible output values.

{# After: #}
{% if value|length == 4 %}...{% endif %}
{% if value|length == 4 %}True{% else %}False{% endif %} ← Much clearer
but also allows customising the output values.
}}}

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

Django

unread,
Jul 22, 2022, 6:06:05 PM7/22/22
to django-...@googlegroups.com
#33864: Deprecate length_is template filter in favor of length.
-------------------------------------+-------------------------------------
Reporter: Nick Pope | Owner: Nick Pope
Type: | Status: assigned
Cleanup/optimization |
Component: Template system | Version: dev
Severity: Normal | Resolution:
Keywords: length_is, length, | Triage Stage:
template, filter | Unreviewed
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/15869 PR]

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

Django

unread,
Jul 23, 2022, 1:03:29 AM7/23/22
to django-...@googlegroups.com
#33864: Deprecate length_is template filter in favor of length.
-------------------------------------+-------------------------------------
Reporter: Nick Pope | Owner: Nick Pope
Type: | Status: assigned
Cleanup/optimization |
Component: Template system | Version: dev
Severity: Normal | Resolution:
Keywords: length_is, length, | Triage Stage: Accepted
template, filter |

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/33864#comment:2>

Django

unread,
Jul 23, 2022, 5:41:42 AM7/23/22
to django-...@googlegroups.com
#33864: Deprecate length_is template filter in favor of length.
-------------------------------------+-------------------------------------
Reporter: Nick Pope | Owner: Nick Pope
Type: | Status: assigned
Cleanup/optimization |
Component: Template system | Version: dev
Severity: Normal | Resolution:
Keywords: length_is, length, | Triage Stage: Accepted
template, filter |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Nick Pope:

Old description:

> The `length_is` template filter is a vestige from the days of the `{%
> ifequal %}` and `{% ifnotequal %}` days before `{% if %}` arrived with
> support for comparison with operators. Even the example in the
> documentation (see
> [https://docs.djangoproject.com/en/4.0/ref/templates/builtins/#length-is
> here]) is poor: `{{ value|length_is:"4" }}` will only return one of three
> possible values - `True`, `False`, or `""`, the empty string being for
> errors in the provided values.
>
> It seems to me that it would be better to encourage use of the `length`
> template filter with the `{% if %}` template tag which can provide more
> flexibility:
>
> {{{#!django
> {# Before: #}
> {% if value|length_is:"4" %}...{% endif %}
> {{ value|length_is:"4" }} ← This is of dubious use given the restricted
> set of possible output values.
>
> {# After: #}
> {% if value|length == 4 %}...{% endif %}
> {% if value|length == 4 %}True{% else %}False{% endif %} ← Much clearer
> but also allows customising the output values.
> }}}

New description:

The `length_is` template filter is a vestige from the days of the `{%

ifequal %}` and `{% ifnotequal %}` tags before `{% if %}` arrived with


support for comparison with operators. Even the example in the
documentation (see
[https://docs.djangoproject.com/en/4.0/ref/templates/builtins/#length-is
here]) is poor: `{{ value|length_is:"4" }}` will only return one of three
possible values - `True`, `False`, or `""`, the empty string being for
errors in the provided values.

It seems to me that it would be better to encourage use of the `length`
template filter with the `{% if %}` template tag which can provide more
flexibility:

{{{#!django
{# Before: #}
{% if value|length_is:"4" %}...{% endif %}
{{ value|length_is:"4" }} ← This is of dubious use given the restricted
set of possible output values.

{# After: #}
{% if value|length == 4 %}...{% endif %}
{% if value|length == 4 %}True{% else %}False{% endif %} ← Much clearer
but also allows customising the output values.
}}}

--

--
Ticket URL: <https://code.djangoproject.com/ticket/33864#comment:3>

Django

unread,
Jul 23, 2022, 6:38:27 AM7/23/22
to django-...@googlegroups.com
#33864: Deprecate length_is template filter in favor of length.
-------------------------------------+-------------------------------------
Reporter: Nick Pope | Owner: Nick Pope
Type: | Status: assigned
Cleanup/optimization |
Component: Template system | Version: dev
Severity: Normal | Resolution:
Keywords: length_is, length, | Triage Stage: Ready for
template, filter | checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/33864#comment:4>

Django

unread,
Jul 23, 2022, 7:15:34 AM7/23/22
to django-...@googlegroups.com
#33864: Deprecate length_is template filter in favor of length.
-------------------------------------+-------------------------------------
Reporter: Nick Pope | Owner: Nick Pope
Type: | Status: closed

Cleanup/optimization |
Component: Template system | Version: dev
Severity: Normal | Resolution: fixed

Keywords: length_is, length, | Triage Stage: Ready for
template, filter | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

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


Comment:

In [changeset:"4d4bf55e0ea849476f7e3abfeb018c338f18a9b4" 4d4bf55]:
{{{
#!CommitTicketReference repository=""
revision="4d4bf55e0ea849476f7e3abfeb018c338f18a9b4"
Fixed #33864 -- Deprecated length_is template filter.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33864#comment:5>

Django

unread,
Sep 18, 2023, 4:12:52 PM9/18/23
to django-...@googlegroups.com
#33864: Deprecate length_is template filter in favor of length.
-------------------------------------+-------------------------------------
Reporter: Nick Pope | Owner: Nick Pope
Type: | Status: closed
Cleanup/optimization |
Component: Template system | Version: dev
Severity: Normal | Resolution: fixed
Keywords: length_is, length, | Triage Stage: Ready for
template, filter | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"14ef92fa9e87a77cd3642235387e6f683048046b" 14ef92f]:
{{{
#!CommitTicketReference repository=""
revision="14ef92fa9e87a77cd3642235387e6f683048046b"
Refs #33864 -- Removed length_is template filter per deprecation timeline.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33864#comment:6>

Reply all
Reply to author
Forward
0 new messages