Opened 3 years ago

Closed 3 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 3 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 Changed 3 years ago by Tim Graham

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)?

Changed 3 years ago by JOSEPH KIM

Attachment: template_bug.zip added

comment:2 Changed 3 years ago by Tim Graham

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.

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

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 Changed 3 years ago by Tim Graham

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 Changed 3 years ago by Vincenzo Pandolfo

Owner: changed from nobody to Vincenzo Pandolfo
Status: newassigned

comment:6 Changed 3 years ago by Vincenzo Pandolfo

Has patch: set

comment:7 Changed 3 years ago by Tim Graham

Patch needs improvement: set

Left comments for improvement.

comment:8 Changed 3 years ago by Tim Graham

Patch needs improvement: unset

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

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