Opened 8 years ago

Closed 8 years ago

#26041 closed Bug (needsinfo)

Flattening a Context object can fail

Reported by: James Addison Owned by: nobody
Component: Template system Version: 1.9
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

I believe this is related to https://code.djangoproject.com/ticket/24765.

Sample project attached, requires django-contrib-comments. Steps:

  1. extract sample project
  2. pip install requirements in virtualenv
  3. run migrations
  4. run runserver
  5. view http://localhost:8000/1/

Note that 'master' of django-contrib-comments uses flatten instead of its v1.6.2 (which is what's on PyPi) current code which performs the same functionality. It fails the same way in master and v1.6.2.

Here is the traceback when using django-contrib-comments 'master' branch:

Environment:


Request Method: GET
Request URL: http://localhost:8000/1/

Django Version: 1.9.1
Python Version: 2.7.10
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.sites',
 'django_comments',
 'blog']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']


Template error:
In template /Users/jaddison/projects/djangocontext/blog/templates/blog/blogitem.html, error at line 0
   dictionary update sequence element #0 has length 3; 2 is required   1 : {% load blogtags comments %}
   2 : <!DOCTYPE html>
   3 : <html lang="en">
   4 : <head>
   5 :     <meta charset="UTF-8">
   6 :     <title>Title</title>
   7 : </head>
   8 : <body>
   9 : {{ item.text }}
   10 : {% do_nothing_special_tag %}


Traceback:

File "/Users/jaddison/.virtualenvs/djangocontext/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  149.                     response = self.process_exception_by_middleware(e, request)

File "/Users/jaddison/.virtualenvs/djangocontext/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/Users/jaddison/projects/djangocontext/blog/views.py" in view_item
  8.     return render(request, 'blog/blogitem.html', {'item':item})

File "/Users/jaddison/.virtualenvs/djangocontext/lib/python2.7/site-packages/django/shortcuts.py" in render
  67.             template_name, context, request=request, using=using)

File "/Users/jaddison/.virtualenvs/djangocontext/lib/python2.7/site-packages/django/template/loader.py" in render_to_string
  97.         return template.render(context, request)

File "/Users/jaddison/.virtualenvs/djangocontext/lib/python2.7/site-packages/django/template/backends/django.py" in render
  95.             return self.template.render(context)

File "/Users/jaddison/.virtualenvs/djangocontext/lib/python2.7/site-packages/django/template/base.py" in render
  206.                     return self._render(context)

File "/Users/jaddison/.virtualenvs/djangocontext/lib/python2.7/site-packages/django/template/base.py" in _render
  197.         return self.nodelist.render(context)

File "/Users/jaddison/.virtualenvs/djangocontext/lib/python2.7/site-packages/django/template/base.py" in render
  988.                 bit = node.render_annotated(context)

File "/Users/jaddison/.virtualenvs/djangocontext/lib/python2.7/site-packages/django/template/base.py" in render_annotated
  955.             return self.render(context)

File "/Users/jaddison/.virtualenvs/djangocontext/lib/python2.7/site-packages/django/template/library.py" in render
  243.         return t.render(new_context)

File "/Users/jaddison/.virtualenvs/djangocontext/lib/python2.7/site-packages/django/template/base.py" in render
  208.                 return self._render(context)

File "/Users/jaddison/.virtualenvs/djangocontext/lib/python2.7/site-packages/django/template/base.py" in _render
  197.         return self.nodelist.render(context)

File "/Users/jaddison/.virtualenvs/djangocontext/lib/python2.7/site-packages/django/template/base.py" in render
  988.                 bit = node.render_annotated(context)

File "/Users/jaddison/.virtualenvs/djangocontext/lib/python2.7/site-packages/django/template/base.py" in render_annotated
  955.             return self.render(context)

File "/Users/jaddison/.virtualenvs/djangocontext/src/django-comments/django_comments/templatetags/comments.py" in render
  181.             context_dict = context.flatten()

File "/Users/jaddison/.virtualenvs/djangocontext/lib/python2.7/site-packages/django/template/context.py" in flatten
  120.             flat.update(d)

Exception Type: ValueError at /1/
Exception Value: dictionary update sequence element #0 has length 3; 2 is required

Definitely has to do with running render_comment_form from within a custom inclusion_tag template.

Attachments (1)

sample_project.tgz (3.4 KB ) - added by James Addison 8 years ago.
sample project demonstrating the bug

Download all attachments as: .zip

Change History (2)

by James Addison, 8 years ago

Attachment: sample_project.tgz added

sample project demonstrating the bug

comment:1 by Tim Graham, 8 years ago

Resolution: needsinfo
Status: newclosed

The reporter is still investigating this to determine if it's a bug in Django and not in the application.

Note: See TracTickets for help on using tickets.
Back to Top