[Django] #26606: 'string_if_invalid' option does not work with custom filter

20 views
Skip to first unread message

Django

unread,
May 12, 2016, 4:16:32 AM5/12/16
to django-...@googlegroups.com
#26606: 'string_if_invalid' option does not work with custom filter
---------------------------+-----------------------------------------------
Reporter: JosephDev | Owner: nobody
Type: Bug | Status: new
Component: Template | Version: 1.9
system |
Severity: Normal | Keywords: template, custom template filter
Triage Stage: | Has patch: 0
Unreviewed |
Easy pickings: 0 | UI/UX: 0
---------------------------+-----------------------------------------------
I use 'string_if_invalid' option to debug invalid context variable.

However, custom filter does not work when a context variable is invalid.

I attached sample project and you can see custom filter works when the
context variables is valid.

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

Django

unread,
May 12, 2016, 4:17:35 AM5/12/16
to django-...@googlegroups.com
#26606: 'string_if_invalid' option does not work with custom filter
-----------------------------------------------+---------------------------

Reporter: JosephDev | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: 1.9
Severity: Normal | Resolution:

Keywords: template, custom template filter | Triage Stage:
| Unreviewed
Has patch: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------------+---------------------------
Changes (by JosephDev):

* Attachment "invalid_string.zip" added.

sample project of custom filter with 'string if invalid' option

Django

unread,
May 12, 2016, 4:34:11 AM5/12/16
to django-...@googlegroups.com
#26606: 'string_if_invalid' option does not work with custom filter
-------------------------------------+-------------------------------------

Reporter: JosephDev | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: 1.9
Severity: Normal | Resolution:
Keywords: template, custom | Triage Stage:
template filter | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by JosephDev):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

tested other filters like 'lower' but, it doesn't work with other filters
either.

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

Django

unread,
May 12, 2016, 11:42:06 AM5/12/16
to django-...@googlegroups.com
#26606: 'string_if_invalid' option does not work with custom filter
-------------------------------------+-------------------------------------

Reporter: JosephDev | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: 1.9
Severity: Normal | Resolution:
Keywords: template, custom | Triage Stage:
template filter | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timgraham):

I see this output. What output do you expect?
{{{
with filter
__FOO__
filter works with valid foo context
with tag
tag works with __FOO__
tag works with valid foo context
}}}

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

Django

unread,
May 12, 2016, 11:50:45 AM5/12/16
to django-...@googlegroups.com
#26606: 'string_if_invalid' option does not work with custom filter
-------------------------------------+-------------------------------------

Reporter: JosephDev | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: 1.9
Severity: Normal | Resolution:
Keywords: template, custom | Triage Stage:
template filter | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by JosephDev):

if filter works with "string_if_invalid" option
the output should be

{{{
with filter
filter works with __FOO__


filter works with valid foo context
with tag
tag works with __FOO__
tag works with valid foo context
}}}

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

Django

unread,
May 12, 2016, 12:15:36 PM5/12/16
to django-...@googlegroups.com
#26606: 'string_if_invalid' option does not work with custom filter
-------------------------------------+-------------------------------------

Reporter: JosephDev | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: 1.9
Severity: Normal | Resolution:
Keywords: template, custom | Triage Stage:
template filter | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timgraham):

I don't see an advantage to running `string_if_valid` through template
filters -- they might transform the value to some other output which would
make it more difficult debug.

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

Django

unread,
May 12, 2016, 12:34:10 PM5/12/16
to django-...@googlegroups.com
#26606: 'string_if_invalid' option does not work with custom filter
-------------------------------------+-------------------------------------

Reporter: JosephDev | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: 1.9
Severity: Normal | Resolution:
Keywords: template, custom | Triage Stage:
template filter | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by JosephDev):

"string_if_invalid" option works perfectly with context variables,
however, with request parameters, it makes redundant code.

Actually, I am supposed to get null string ("") when I don't need string
of "string_if_invalid" especially handle request parameters.

for example, to get null string (or to escape invalid string)

as is
{{{
<input name="foo" type="text" value="{% if request.GET.foo %}{{
request.GET.foo }}{% endif %}">
}}}

want to
{{{
<input name="foo" type="text" value="{{ request.GET.foo|or_null }}">
}}}

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

Django

unread,
May 12, 2016, 1:14:49 PM5/12/16
to django-...@googlegroups.com
#26606: 'string_if_invalid' option does not work with custom filter
-------------------------------------+-------------------------------------

Reporter: JosephDev | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: 1.9
Severity: Normal | Resolution:
Keywords: template, custom | Triage Stage:
template filter | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timgraham):

I'm having trouble understanding how your last comment relates to our
previous discussion.

Have you read the
"[https://docs.djangoproject.com/en/stable/ref/templates/api/#how-invalid-
variables-are-handled For debug purposes only]" note about
`string_if_invalid`? I get the sense that you may be trying to use
`string_if_invalid` for more than it's designed for.

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

Django

unread,
May 14, 2016, 1:14:02 AM5/14/16
to django-...@googlegroups.com
#26606: 'string_if_invalid' option does not work with custom filter
-------------------------------------+-------------------------------------
Reporter: JosephDev | Owner: nobody
Type: Bug | Status: closed

Component: Template system | Version: 1.9
Severity: Normal | Resolution: invalid

Keywords: template, custom | Triage Stage:
template filter | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by JosephDev):

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


--
Ticket URL: <https://code.djangoproject.com/ticket/26606#comment:7>

Reply all
Reply to author
Forward
0 new messages