Code

Opened 6 years ago

Closed 5 years ago

Last modified 3 years ago

#8725 closed (fixed)

TemplateSyntaxError at /admin/ with [8760]

Reported by: kmtracey Owned by: mtredinnick
Component: Core (Other) Version: 1.0
Severity: Keywords:
Cc: ville@…, carl@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I get TemplateSyntaxError at /admin/ after updating to current this AM, isolated to being introduced in [8760]; backing up to [8759] makes it go away. Full cut-and-paste info:

Environment:

Request Method: GET
Request URL: http://lbox:8000/admin/
Django Version: 1.0-beta_2-SVN-8760
Python Version: 2.5.1
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.admin',
 'django.contrib.admindocs',
 'django.contrib.sites',
 'django.contrib.humanize',
 'xword.crossword']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.doc.XViewMiddleware')


Template error:
In template /home/kmt/tmp/django/trunk/django/contrib/admin/templates/admin/base.html, error at line 25
   Caught an exception while rendering: 
   15 : <!-- Container -->
   16 : <div id="container">
   17 : 
   18 :     {% if not is_popup %}
   19 :     <!-- Header -->
   20 :     <div id="header">
   21 :         <div id="branding">
   22 :         {% block branding %}{% endblock %}
   23 :         </div>
   24 :         {% if user.is_authenticated and user.is_staff %}
   25 :         <div id="user-tools">{% trans 'Welcome,' %} <strong>{% if user.first_name %}{{ user.first_name|escape }}{% else %}{{ user.username }}{% endif %}</strong>. {% block userlinks %} {% url django-admindocs-docroot as docsroot %} {% if docsroot %}<a href="{{ docsroot }}">{% trans 'Documentation' %}</a> / {% endif %}<a href="{{ root_path }}password_change/">{% trans 'Change password' %}</a> / <a href="{{ root_path }}logout/">{% trans 'Log out' %}</a>{% endblock %}</div>
   26 :         {% endif %}
   27 :         {% block nav-global %}{% endblock %}
   28 :     </div>
   29 :     <!-- END Header -->
   30 :     {% block breadcrumbs %}<div class="breadcrumbs"><a href="/">{% trans 'Home' %}</a>{% if title %} &rsaquo; {{ title|escape }}{% endif %}</div>{% endblock %}
   31 :     {% endif %}
   32 : 
   33 :         {% if messages %}
   34 :         <ul class="messagelist">{% for message in messages %}<li>{{ message|escape }}</li>{% endfor %}</ul>
   35 :         {% endif %}

Traceback:
File "/home/kmt/tmp/django/trunk/django/core/handlers/base.py" in get_response
  86.                 response = callback(request, *callback_args, **callback_kwargs)
File "/home/kmt/tmp/django/trunk/django/contrib/admin/sites.py" in root
  160.             return self.index(request)
File "/home/kmt/tmp/django/trunk/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)
File "/home/kmt/tmp/django/trunk/django/contrib/admin/sites.py" in index
  342.             context_instance=template.RequestContext(request)
File "/home/kmt/tmp/django/trunk/django/shortcuts/__init__.py" in render_to_response
  18.     return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/home/kmt/tmp/django/trunk/django/template/loader.py" in render_to_string
  107.     return t.render(context_instance)
File "/home/kmt/tmp/django/trunk/django/template/__init__.py" in render
  176.         return self.nodelist.render(context)
File "/home/kmt/tmp/django/trunk/django/template/__init__.py" in render
  756.                 bits.append(self.render_node(node, context))
File "/home/kmt/tmp/django/trunk/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/home/kmt/tmp/django/trunk/django/template/loader_tags.py" in render
  97.         return compiled_parent.render(context)
File "/home/kmt/tmp/django/trunk/django/template/__init__.py" in render
  176.         return self.nodelist.render(context)
File "/home/kmt/tmp/django/trunk/django/template/__init__.py" in render
  756.                 bits.append(self.render_node(node, context))
File "/home/kmt/tmp/django/trunk/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/home/kmt/tmp/django/trunk/django/template/loader_tags.py" in render
  97.         return compiled_parent.render(context)
File "/home/kmt/tmp/django/trunk/django/template/__init__.py" in render
  176.         return self.nodelist.render(context)
File "/home/kmt/tmp/django/trunk/django/template/__init__.py" in render
  756.                 bits.append(self.render_node(node, context))
File "/home/kmt/tmp/django/trunk/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/home/kmt/tmp/django/trunk/django/template/defaulttags.py" in render
  245.                     return self.nodelist_true.render(context)
File "/home/kmt/tmp/django/trunk/django/template/__init__.py" in render
  756.                 bits.append(self.render_node(node, context))
File "/home/kmt/tmp/django/trunk/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/home/kmt/tmp/django/trunk/django/template/defaulttags.py" in render
  255.             return self.nodelist_true.render(context)
File "/home/kmt/tmp/django/trunk/django/template/__init__.py" in render
  756.                 bits.append(self.render_node(node, context))
File "/home/kmt/tmp/django/trunk/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/home/kmt/tmp/django/trunk/django/template/loader_tags.py" in render
  24.         result = self.nodelist.render(context)
File "/home/kmt/tmp/django/trunk/django/template/__init__.py" in render
  756.                 bits.append(self.render_node(node, context))
File "/home/kmt/tmp/django/trunk/django/template/debug.py" in render_node
  81.             raise wrapped

Exception Type: TemplateSyntaxError at /admin/
Exception Value: Caught an exception while rendering: 

Original Traceback (most recent call last):
  File "/home/kmt/tmp/django/trunk/django/template/debug.py", line 71, in render_node
    result = node.render(context)
  File "/home/kmt/tmp/django/trunk/django/template/defaulttags.py", line 373, in render
    url = reverse(self.view_name, args=args, kwargs=kwargs)
  File "/home/kmt/tmp/django/trunk/django/core/urlresolvers.py", line 250, in reverse
    *args, **kwargs)))
  File "/home/kmt/tmp/django/trunk/django/core/urlresolvers.py", line 226, in reverse
    possibilities, pattern = self.reverse_dict.get(lookup_view, [(), ()])
  File "/home/kmt/tmp/django/trunk/django/core/urlresolvers.py", line 159, in _get_reverse_dict
    parent = normalize(pattern.regex.pattern)
  File "/home/kmt/tmp/django/trunk/django/utils/regex_helper.py", line 77, in normalize
    ch, escaped = pattern_iter.next()
StopIteration

There's nothing particularly fancy about my admin setup (no over-ridden templates or anything, so far as I recall). My own views work fine, so far as I've checked. If this is not generally recreatable let me know what info would be most helpful to track it down.

Attachments (2)

regex_helper_r8761.diff (584 bytes) - added by oggy 6 years ago.
regex_helper_r8761_with_test.diff (1.2 KB) - added by carljm 6 years ago.
added regression test to patch

Download all attachments as: .zip

Change History (18)

comment:1 Changed 6 years ago by kmtracey

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Just a note, since you can't see the debug page highlighting in the ticket, it the {% url django-admindocs-docroot as docsroot %} on line 25 that is highlighted. I do have admindocs in my INSTALLED_APPS and documentation was working as of yesterday. Removing it from INSTALLED_APPS and its urlpattern ((r'^admin/doc/', include('django.contrib.admindocs.urls')),) from urls.py, though, doesn't appear to change anything, I still get the error on any attempt to access an admin page.

comment:2 Changed 6 years ago by jacob

  • Component changed from Uncategorized to Admin interface
  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 6 years ago by oggy

  • Component changed from Admin interface to Core framework

I upgraded to r8760 today and all hell broke loose with reversing my own views. Fixing one line in regex_helper seems to do the trick, and should hopefully fix this one too.

Changed 6 years ago by oggy

comment:4 Changed 6 years ago by Uninen

  • Cc ville@… added

#8726 might be related to this, although the exception is different.

comment:5 Changed 6 years ago by carljm

  • Cc carl@… added

comment:6 Changed 6 years ago by carljm

I can reproduce this problem (in my own views/templates), and the attached patch fixes it for me.

comment:7 Changed 6 years ago by carljm

I've tracked this problem down to the use of an empty regex in a URLConf. This is useful in order to include an application's urls with no prefix; i.e. something like this at the end of a urlpatterns:

url(r'', include('some_app.urls'))

Based on this, I think the attached patch is the correct fix. The first call to next() will raise StopIteration if the pattern is zero-length, so it needs to be within the try block.

comment:8 Changed 6 years ago by mtredinnick

  • Owner changed from nobody to mtredinnick
  • Status changed from new to assigned

Changed 6 years ago by carljm

added regression test to patch

comment:9 Changed 6 years ago by Alex

  • Resolution set to fixed
  • Status changed from assigned to closed

Fixed in r8763.

comment:10 Changed 6 years ago by FlorentV

Hello,

I get the exact same Template Error with 1.0 RC1. Is that normal (fix not in RC1)?

Since it blocked any use of the admin, I hacked the admin/base.html template, removing the whole link to the documentation.

comment:11 Changed 6 years ago by jacob

FlorentV: can you please post your whole error? Make sure to use the "show copy/paste error" button, and paste the error between {{{ and }}} (three braces) so that Trac displays it OK.

comment:12 Changed 6 years ago by FlorentV

jacob: my bad, it was just a problem with a bad urlconf. I had a reference to a view that didn't “exist” since it was in an app I had commented out in INSTALLED_APPS. So basically it was the same problem as in this ticket: http://code.djangoproject.com/ticket/8854

Of course it's not a bug, just a mistake on my part. But it's too bad the error I got was a not-so-helpful template error. If a reference to a non-existing view in urlconf breaks some important feature of the framework, maybe Django should catch this error earlier on and display a specific error?

comment:13 Changed 5 years ago by atilev@…

  • Has patch set
  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Version changed from SVN to 1.0

Hi,
I get this same error. It appears very sporadic. When I'm in the admin page if I hit refresh it comes up. My stack trace is identical to the previuse users.

I looked in my regex_helper.py and it already seems to have the fix in place

try:

ch, escaped = pattern_iter.next()

except StopIteration:

return zip([], [[]])

I do have a

(r'$', '/index.html'),

in my urls.py

other than that nothing fancy.

comment:14 Changed 5 years ago by gwilson

  • Resolution set to fixed
  • Status changed from reopened to closed

Perhaps you have not defined a view that is referenced in your URLconf. Please take your issue to the django-users list.

comment:15 Changed 5 years ago by anibal

I got this problem today with django-svn. I found that the error only appear when my database is empty, after insert some users and the fixture of my main app the error goes away. Weird.

comment:16 Changed 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.