|
#18742: Template tag length returns invalid value
---------------------------------+-------------------- Reporter: lukaslipka@… | Owner: nobody Type: Bug | Status: new Component: Template system | Version: 1.4 Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Easy pickings: 0 | UI/UX: 0 ---------------------------------+-------------------- The length template tag shows some weird behavior for undefined values. A condition such as evaluates true, when blabla is undefined: {{{ {% if blabla|length > 5 %} {{ blabla|length }} {% endif %} }}} Even though it evaluates true, the output of {{ blabla|length }} is 0. -- Ticket URL: <https://code.djangoproject.com/ticket/18742> 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 post to this group, send email to [hidden email]. To unsubscribe from this group, send email to [hidden email]. For more options, visit https://groups.google.com/groups/opt_out. |
|
#18742: Template tag length returns invalid value
---------------------------------+-------------------------------------- Reporter: lukaslipka@… | Owner: nobody Type: Bug | Status: new Component: Template system | Version: 1.4 Severity: Normal | Resolution: 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 kmtracey): * needs_better_patch: => 0 * needs_tests: => 0 * needs_docs: => 0 Comment: Not sure what to do about this one. During the evaluation of the filter expression condition in the if tag, `blabla` is evaluated as a `TemplateLiteral`, which resolves the value in the context specifying `ignore_failures=True`: https://github.com/django/django/blob/stable/1.4.x/django/template/defaulttags.py#L814 With ignore_failures True, the value resolves to None instead of the empty string it would resolve to if ignore_failures was False. None as the value for the length filter causes length to return an empty string: https://github.com/django/django/blob/stable/1.4.x/django/template/defaultfilters.py#L540 Subsequently when evaluating `{{ blabla|length }}`, `blabla` is resolved with ignore_failures False, so it resolve to the empty string. And the length of the empty string is 0. Changing `TemplateLiteral` eval to not specify ignore_failures=True breaks a bunch of if tag template tests. Changing the length filter to return 0 instead of the empty string for invalid inputs breaks a bunch of length filter tests. Whether either of these changes would break real code I'm not sure (length returning an empty string, in particular, seems an odd thing to me...though I can see how that may actually be used to display no output at all for non-existent data rather than 0...so I suspect changing that would in fact break things in some real code). Either of them does make the template fragment in the description behave sanely, but neither is backwards-compatible. -- Ticket URL: <https://code.djangoproject.com/ticket/18742#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 post to this group, send email to [hidden email]. To unsubscribe from this group, send email to [hidden email]. For more options, visit https://groups.google.com/groups/opt_out. |
|
In reply to this post by Django
#18742: Template tag length returns invalid value
-------------------------------------+------------------------------------- Reporter: lukaslipka@… | Owner: nobody Type: Bug | Status: new Component: Template system | Version: 1.4 Severity: Normal | Resolution: Keywords: | Triage Stage: Design Has patch: 0 | decision needed Needs tests: 0 | Needs documentation: 0 Easy pickings: 0 | Patch needs improvement: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Changes (by melinath): * stage: Unreviewed => Design decision needed Comment: It sounds like this is maybe DDN. My two cents: Changing |length to return 0 instead of an empty string makes the most sense to me. It may break some templates, true, but it wouldn't be that hard to fix. -- Ticket URL: <https://code.djangoproject.com/ticket/18742#comment:2> 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 post to this group, send email to [hidden email]. To unsubscribe from this group, send email to [hidden email]. For more options, visit https://groups.google.com/groups/opt_out. |
|
In reply to this post by Django
#18742: Template tag length returns invalid value
-------------------------------------+------------------------------------- Reporter: lukaslipka@… | Owner: nobody Type: Bug | Status: closed Component: Template system | Version: 1.4 Severity: Normal | Resolution: duplicate Keywords: | Triage Stage: Design Has patch: 0 | decision needed Needs tests: 0 | Needs documentation: 0 Easy pickings: 0 | Patch needs improvement: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Changes (by bmispelon): * status: new => closed * resolution: => duplicate Comment: This is a duplicate of #18400. -- Ticket URL: <https://code.djangoproject.com/ticket/18742#comment:3> 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 [hidden email]. To post to this group, send email to [hidden email]. For more options, visit https://groups.google.com/groups/opt_out. |
| Powered by Nabble | Edit this page |
