Opened 12 years ago
Closed 12 years ago
#19621 closed Bug (wontfix)
templates suppress TypeErrors from comparisons
Reported by: | leftmoose | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | 1.4 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
even with TEMPLATE_DEBUG = True
,
passing e.g. a DateTime
to a template and doing {% if now > 2 %}
is silently coerced to false, rather than raising the TypeError
(in my case it was slightly less obvious, accidentally comparing naive and a time zone aware datetimes)
Note:
See TracTickets
for help on using tickets.
Thanks for the report!
In general, the philosophy of the Django template language is to suppress errors, on the theory that template designers should not be able to cause crashes. So I think this is consistent with how the rest of the template language operates.
(Personally, I don't buy the rationale for that philosophy, as it is always possible for a template designer to make a site effectively non-functional one way or another. But changing the approach of the entire template language to error-suppression would require a comprehensive review of current behavior and a proposal on the mailing list; it shouldn't happen piecemeal via tickets for individual cases.)