[Django] #26886: Wrong warnings during template rendering

80 views
Skip to first unread message

Django

unread,
Jul 10, 2016, 3:35:47 PM7/10/16
to django-...@googlegroups.com
#26886: Wrong warnings during template rendering
---------------------------------+------------------------
Reporter: liminspace | Owner: liminspace
Type: Bug | Status: new
Component: Template system | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------
There is template:
{{{
<div style="{{ style }}"></div>
}}}
and code:
{{{
render(request, 'template.html', context={'style': "background-image:
url('image.png');"})
}}}

After run it I get some strange console output:

{{{
Exception while resolving variable 'name' in template 'unknown'.
Traceback (most recent call last):
File ".../.virtualenvs/project/local/lib/python2.7/site-
packages/django/template/base.py", line 905, in _resolve_lookup
(bit, current)) # missing attribute
VariableDoesNotExist: Failed lookup for key [name] in
u'<RegexURLResolver <RegexURLPattern list> (admin:admin) ^admin/>'
Exception while resolving variable 'name' in template 'unknown'.
Traceback (most recent call last):
File ".../.virtualenvs/project/local/lib/python2.7/site-
packages/django/template/base.py", line 905, in _resolve_lookup
(bit, current)) # missing attribute
VariableDoesNotExist: Failed lookup for key [name] in
u"<RegexURLResolver <module 'django.contrib.admindocs.urls' from
'.../.virtualenvs/project/local/lib/python2.7/site-
packages/django/contrib/admindocs/urls.pyc'> (None:None) ^admin/doc/>"
....
etc.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26886>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 10, 2016, 8:10:57 PM7/10/16
to django-...@googlegroups.com
#26886: Wrong warnings during template rendering
---------------------------------+--------------------------------------
Reporter: liminspace | Owner: liminspace
Type: Bug | Status: closed

Component: Template system | Version: 1.9
Severity: Normal | Resolution: needsinfo
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 timgraham):

* status: new => closed
* needs_docs: => 0
* resolution: => needsinfo
* needs_tests: => 0
* needs_better_patch: => 0


Comment:

Could you please provide a sample project to reproduce the issue? That
minimal view and template doesn't create that error if I add it to the
tutorial's project so we're probably missing some steps to reproduce.

--
Ticket URL: <https://code.djangoproject.com/ticket/26886#comment:1>

Django

unread,
Sep 28, 2016, 12:43:42 AM9/28/16
to django-...@googlegroups.com
#26886: Wrong warnings during template rendering
---------------------------------+--------------------------------------
Reporter: None | Owner: None

Type: Bug | Status: new
Component: Template system | Version: 1.9
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 nrogers64):

* status: closed => new
* resolution: needsinfo =>


Comment:

I wasn't the one to report this bug, but I ran into the same thing. I made
a fresh Django 1.10.1 project and added this to settings.py:


{{{
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
'loggers': {
'django.template': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': False,
},
}
}
}}}

That is the only code I added. I then did the initial migrate and started
runserver. Then, in another Terminal tab, I ran `curl
http://localhost:8001/favicon.ico`, which resulted in a "Page not found at
/favicon.ico", as expected. But this was in the output of runserver:


{{{
Exception while resolving variable 'name' in template 'unknown'.
Traceback (most recent call last):
File ".../.virtualenvs/project/local/lib/python2.7/site-

packages/django/template/base.py", line 907, in _resolve_lookup


(bit, current)) # missing attribute
VariableDoesNotExist: Failed lookup for key [name] in u'<RegexURLResolver
<RegexURLPattern list> (admin:admin) ^admin/>'
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26886#comment:2>

Django

unread,
Sep 28, 2016, 10:46:01 AM9/28/16
to django-...@googlegroups.com
#26886: Wrong warnings during template rendering
---------------------------------+--------------------------------------
Reporter: None | Owner: None
Type: Bug | Status: new
Component: Error reporting | Version: 1.9
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 Tim Graham):

* component: Template system => Error reporting


Comment:

The error comes from the
[https://github.com/django/django/blob/a44fc008c4e38fadef04021fdba564949f1aee3a/django/views/debug.py#L1191
TECHNICAL_404_TEMPLATE]: `{% if forloop.last and pat.name %}[name='{{
pat.name }}']{% endif %}`

There isn't a problem besides the confusing logging. The error occurs
because `RegexURLResolver` doesn't have a name attribute so the exception
is expected. Only a `RegexURLPattern` has a `name` in that loop. I'm not
sure if there's a simple solution to avoid that exception logging (added
in #18773).

--
Ticket URL: <https://code.djangoproject.com/ticket/26886#comment:3>

Django

unread,
Sep 28, 2016, 12:37:52 PM9/28/16
to django-...@googlegroups.com
#26886: TECHNICAL_404_TEMPLATE logs an "Exception while resolving variable" warning
--------------------------------------+------------------------------------
Reporter: None | Owner: None
Type: Cleanup/optimization | Status: new

Component: Error reporting | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted


Comment:

Accepting for further thought.

--
Ticket URL: <https://code.djangoproject.com/ticket/26886#comment:4>

Django

unread,
Mar 15, 2017, 2:10:23 PM3/15/17
to django-...@googlegroups.com
#26886: TECHNICAL_404_TEMPLATE logs an "Exception while resolving variable" warning
--------------------------------------+------------------------------------
Reporter: None | Owner: None
Type: Cleanup/optimization | Status: new
Component: Error reporting | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Abbott):

* cc: tabbott@… (added)


Comment:

We were seeing this a lot in the Zulip development environment and found
it pretty confusing for new contributors, so we worked around it using
https://github.com/zulip/zulip/pull/4076.

--
Ticket URL: <https://code.djangoproject.com/ticket/26886#comment:5>

Django

unread,
Mar 16, 2017, 3:04:02 PM3/16/17
to django-...@googlegroups.com
#26886: TECHNICAL_404_TEMPLATE logs an "Exception while resolving variable" warning
--------------------------------------+------------------------------------
Reporter: None | Owner: None
Type: Cleanup/optimization | Status: new
Component: Error reporting | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Tim Graham):

I started a thread on the [https://groups.google.com/d/topic/django-
developers/zdULZcmAWNw/discussion django-developers mailing list] to see
if there might be consensus to remove logging of undefined variables.

--
Ticket URL: <https://code.djangoproject.com/ticket/26886#comment:6>

Django

unread,
Aug 4, 2017, 11:35:27 AM8/4/17
to django-...@googlegroups.com
#26886: TECHNICAL_404_TEMPLATE logs an "Exception while resolving variable" warning
--------------------------------------+------------------------------------
Reporter: None | Owner: None
Type: Cleanup/optimization | Status: new
Component: Error reporting | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Sharmila G Sivakumar):

Hi,

I another developer who has encountered the same issue. I perused the
comments on the mailing list also to see how this would be handled. I
agree with the sentiment that errors need to be raised as they are good
indicators of underlying issues that need to be fixed. That is true even
if, overall, the system works. On the other hand it would be great if the
error can be identified for what it is - An known error raised by django
internals and handled accordingly. Like the contributer Antony King
suggested, a single line capturing the essence of the error would suffice

``
some_app/home.html:32:24: Undefined variable: missing_variable
``

The reason I am suggesting this is, I am using Django 1.11 and the
Template_404's error messages are drowning out all other errors. The error
is basically caused by favicon.ico resulting in a 404. In the process of
development, favicons are the last priority. So, the developers might
have to endure the error messages for a long time. Adding a temporary
favicon is a possibility, but I would rather prefer a `"GET /favicon.ico
HTTP/1.1" 404 4296` message on the console to remind that favicon is not
set :)

I am providing an example of an exception trace from a single favicon 404
error. May be I am doing something wrong too. If so please suggest an
appropriate correction.


Exception while resolving variable 'name' in template 'unknown'.
Traceback (most recent call last):

File "/home/code/product_recco/reddit_env/lib/python3.6/site-
packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/home/code/product_recco/reddit_env/lib/python3.6/site-
packages/django/core/handlers/base.py", line 172, in _get_response
resolver_match = resolver.resolve(request.path_info)
File "/home/code/product_recco/reddit_env/lib/python3.6/site-
packages/django/urls/resolvers.py", line 392, in resolve
raise Resolver404({'tried': tried, 'path': new_path})
django.urls.exceptions.Resolver404: {'tried': [[<RegexURLResolver <module
'debug_toolbar.toolbar' from
'/home/code/product_recco/reddit_env/lib/python3.6/site-
packages/debug_toolbar/toolbar.py'> (djdt:djdt) ^__debug__/>],
[<RegexURLResolver <RegexURLPattern list> (admin:admin) ^admin/>],
[<RegexURLResolver <module 'userssay.urls' from
'/home/code/product_recco/camerasforpros/src/recoapp/userssay/urls.py'>
(None:None) ^>, <RegexURLPattern index ^$>], [<RegexURLResolver <module
'userssay.urls' from
'/home/code/product_recco/camerasforpros/src/recoapp/userssay/urls.py'>
(None:None) ^>, <RegexURLPattern subscribe ^subscribe$>], [<Re
gexURLResolver <module 'userssay.urls' from
'/home/code/product_recco/camerasforpros/src/recoapp/userssay/
urls.py'> (None:None) ^>, <RegexURLPattern search ^search$>],
[<RegexURLResolver <module 'userssay.urls' f
rom
'/home/code/product_recco/camerasforpros/src/recoapp/userssay/urls.py'>
(None:None) ^>, <RegexURLPatte
rn category_most_voted ^categories/(?P<cat_slug>[a-zA-Z0-9-]+)/most-
voted/$>], [<RegexURLResolver <module
'userssay.urls' from
'/home/code/product_recco/camerasforpros/src/recoapp/userssay/urls.py'>
(None:None) ^>, <RegexURLPattern category_most_recent
^categories/(?P<cat_slug>[a-zA-Z0-9-]+)/most-recent/$>], [<RegexU
RLResolver <module 'userssay.urls' from
'/home/code/product_recco/camerasforpros/src/recoapp/userssay/urls
.py'> (None:None) ^>, <RegexURLPattern tag_most_voted
^tags/(?P<tag_slug>[a-zA-Z0-9-]+)/most-voted/$>], [<
RegexURLResolver <module 'userssay.urls' from
'/home/code/product_recco/camerasforpros/src/recoapp/userssa
y/urls.py'> (None:None) ^>, <RegexURLPattern tag_most_recent
^tags/(?P<tag_slug>[a-zA-Z0-9-]+)/most-recent
/$>], [<RegexURLResolver <module 'userssay.urls' from
'/home/code/product_recco/camerasforpros/src/recoapp
/userssay/urls.py'> (None:None) ^>, <RegexURLPattern get_product_info
^product/(?P<id_>[0-9]+)/(?P<slug>[a
-zA-Z0-9-_]+)/$>], [<RegexURLResolver <module 'userssay.urls' from
'/home/code/product_recco/camerasforpros/src/recoapp/userssay/urls.py'>
(None:None) ^>, <RegexURLPattern get_accessories ^accessories/(?P<slug>[a
-zA-Z0-9-_]+)/$>], [<RegexURLResolver <module 'userssay.urls' from
'/home/code/product_recco/camerasforpro
s/src/recoapp/userssay/urls.py'> (None:None) ^>, <RegexURLPattern
django.contrib.sitemaps.views.sitemap ^s
itemap\.xml$>], [<RegexURLPattern None ^static\/(?P<path>.*)$>]], 'path':
'favicon.ico'}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/home/code/product_recco/reddit_env/lib/python3.6/site-
packages/django/template/base.py", line 882
, in _resolve_lookup
current = current[bit]
TypeError: 'RegexURLResolver' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/home/code/product_recco/reddit_env/lib/python3.6/site-
packages/django/template/base.py", line 890
, in _resolve_lookup
current = getattr(current, bit)
AttributeError: 'RegexURLResolver' object has no attribute 'name'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/home/code/product_recco/reddit_env/lib/python3.6/site-
packages/django/template/base.py", line 896, in _resolve_lookup
current = current[int(bit)]
ValueError: invalid literal for int() with base 10: 'name'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/home/code/product_recco/reddit_env/lib/python3.6/site-
packages/django/template/base.py", line 903, in _resolve_lookup


(bit, current)) # missing attribute

django.template.base.VariableDoesNotExist: Failed lookup for key [name] in
"<RegexURLResolver <module 'debug_toolbar.toolbar' from
'/home/code/product_recco/reddit_env/lib/python3.6/site-
packages/debug_toolbar/toolbar.py'> (djdt:djdt) ^__debug__/>"


Exception while resolving variable 'name' in template 'unknown'.
Traceback (most recent call last):

File "/home/code/product_recco/reddit_env/lib/python3.6/site-
packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/home/code/product_recco/reddit_env/lib/python3.6/site-
packages/django/core/handlers/base.py", line 172, in _get_response
resolver_match = resolver.resolve(request.path_info)
File "/home/code/product_recco/reddit_env/lib/python3.6/site-
packages/django/urls/resolvers.py", line 392, in resolve
raise Resolver404({'tried': tried, 'path': new_path})
django.urls.exceptions.Resolver404: {'tried':
[.....................huge..list..of..urls..removed.........................],
'path': 'favicon.ico'}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/home/code/product_recco/reddit_env/lib/python3.6/site-
packages/django/template/base.py", line 882, in _resolve_lookup
current = current[bit]
TypeError: 'RegexURLResolver' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/home/code/product_recco/reddit_env/lib/python3.6/site-
packages/django/template/base.py", line 890, in _resolve_lookup
current = getattr(current, bit)
AttributeError: 'RegexURLResolver' object has no attribute 'name'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/home/code/product_recco/reddit_env/lib/python3.6/site-
packages/django/template/base.py", line 896, in _resolve_lookup
current = current[int(bit)]
ValueError: invalid literal for int() with base 10: 'name'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/home/code/product_recco/reddit_env/lib/python3.6/site-
packages/django/template/base.py", line 903, in _resolve_lookup


(bit, current)) # missing attribute

django.template.base.VariableDoesNotExist: Failed lookup for key [name] in


'<RegexURLResolver <RegexURLPattern list> (admin:admin) ^admin/>'

Not Found: /favicon.ico
"GET /favicon.ico HTTP/1.1" 404 4296

--
Ticket URL: <https://code.djangoproject.com/ticket/26886#comment:7>

Django

unread,
Aug 24, 2017, 11:11:38 AM8/24/17
to django-...@googlegroups.com
#26886: TECHNICAL_404_TEMPLATE logs an "Exception while resolving variable" warning
-------------------------------------+-------------------------------------
Reporter: None | Owner: None
Type: | Status: closed
Cleanup/optimization |

Component: Error reporting | Version: 1.9
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => duplicate


Comment:

I created #28526 to address the problem of verbose, often unhelpful
logging of undefined variables.

--
Ticket URL: <https://code.djangoproject.com/ticket/26886#comment:8>

Reply all
Reply to author
Forward
0 new messages