Opened 9 years ago

Closed 9 years ago

#26365 closed New feature (fixed)

Add a system check to ensure "string_if_invalid" is a string

Reported by: JOSEPH KIM Owned by: Vincenzo Pandolfo
Component: Core (System checks) Version: 1.9
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

template option "string_if_invalid" cannot find error location with including html

for example

index.html

...
{% include "inc_home.html" %}
...

and inc_home.html has an invalid variable, Dajngo raise error at the beginning of index.html

work fine with {% extends %}

Attachments (1)

template_bug.zip (16.6 KB ) - added by JOSEPH KIM 9 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 by Tim Graham, 9 years ago

I can't reproduce this given the information you provided. Could you provide a complete example as a sample project or as a test case for Django's test suite (tests/template_tests)?

by JOSEPH KIM, 9 years ago

Attachment: template_bug.zip added

comment:2 by Tim Graham, 9 years ago

What version of Django are you using? On Django 1.8.x and Django 1.9.x, the sample project is crashing with:

  File "/home/tim/code/django/django/template/base.py", line 1043, in render
    output = self.filter_expression.resolve(context)
  File "/home/tim/code/django/django/template/base.py", line 716, in resolve
    if '%s' in string_if_invalid:
TypeError: argument of type 'bool' is not iterable

If I change the value to a string, e.g. 'string_if_invalid': 'fooo',, I'm seeing that value in the homepage output.

in reply to:  2 comment:3 by JOSEPH KIM, 9 years ago

Replying to timgraham:

What version of Django are you using? On Django 1.8.x and Django 1.9.x, the sample project is crashing with:

  File "/home/tim/code/django/django/template/base.py", line 1043, in render
    output = self.filter_expression.resolve(context)
  File "/home/tim/code/django/django/template/base.py", line 716, in resolve
    if '%s' in string_if_invalid:
TypeError: argument of type 'bool' is not iterable

If I change the value to a string, e.g. 'string_if_invalid': 'fooo',, I'm seeing that value in the homepage output.

1.9.4 and it's intended error. Because, Django raised error but not indicate appropriate location in code if html file is included.

comment:4 by Tim Graham, 9 years ago

Component: Template systemCore (System checks)
Summary: template option "string_if_invalid" can't find error location whit including htmlAdd a system check to ensure "string_if_invalid" is a string
Triage Stage: UnreviewedAccepted
Type: BugNew feature

string_if_invalid must be a string, not a boolean. We could add a system check to catch this mistake.

comment:5 by Vincenzo Pandolfo, 9 years ago

Owner: changed from nobody to Vincenzo Pandolfo
Status: newassigned

comment:6 by Vincenzo Pandolfo, 9 years ago

Has patch: set

comment:7 by Tim Graham, 9 years ago

Patch needs improvement: set

Left comments for improvement.

comment:8 by Tim Graham, 9 years ago

Patch needs improvement: unset

comment:9 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In abf0735:

Fixed #26365 -- Added a system check to ensure "string_is_invalid" is a string.

Note: See TracTickets for help on using tickets.
Back to Top