#17664: Smart `if` tag silencing exceptions plus `QuerySet` caching equals buggy
behaviour.
-------------------------------------+-------------------------------------
Reporter: mrmachine | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: SVN
Severity: Normal | Resolution:
Keywords: smart if tag | Triage Stage:
queryset exception silenced | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by krzysiumed):
* cc: krzysiumed@… (added)
Comment:
The problem is that `QuerySets` are lazy and the exception occures in
different places in these two situations.
Look here:
https://code.djangoproject.com/browser/django/trunk/django/template/defaulttags.py#L269.
Consider the situation with `{% if qs %}`. When the `<IfNode>` is being
rendering, attribute `condition` is `TemplateLiteral` instance with
`text="qs"`. After executing line 274, attribute `match` is `QuerySet`.
There is no exception, because `QuerySets` are lazy. Then line 280
becomes. Method `__nonzero__` of `QuerySet` is being executing and the
exception is being raising at this moment.
Now consider `{% if not qs %}`. Line 274 is being executing. What
happened? Operator `not` is being executing. See
https://code.djangoproject.com/browser/django/trunk/django/template/smartif.py#L81
- all exceptions are caught. `match` is `False`.
The solution may be to change
https://code.djangoproject.com/browser/django/trunk/django/template/smartif.py#L84
- except clause should be less strict and should not catch all exception.
But which ones?
--
Ticket URL: <https://code.djangoproject.com/ticket/17664#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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.