New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ValueError
with 1.6 on some pages only.
#706
Comments
Hi, Thanks for the bug report. Weird that it fails, I suppose our tests don't cover a specific context use case. I'll try to look into that if I have the time, but since support for Django 1.7 or below has been removed in the develop version (as Django dropped 1.7 support recently), it's unlikely we'll fix it. |
Hi @mrmachine , @diox! I've met the same issue. The bug is in Django itself. It is fixed for Related Django issue #26041 (https://code.djangoproject.com/ticket/26041) (the latest, but it has links to previous (original) issue. I hope this will help. |
im getting a very similar error with django 1.8.10 exact same problem ValueError at / just using final_context = self.context seems to fix it |
I'm using django
Expanding on @mrmachine's proposal, the following fix works for me (though I'm not sure if it's the most appropriate): from django import VERSION
...
if VERSION < (1, 8) or VERSION > (1, 9):
final_context = self.context
else:
# Django 1.8 complains about Context being passed to its
# Template.render function.
final_context = self.context.flatten() |
BTW, in my case, the view code that causes the issue is in categories/views.py#L20-L44: def category_detail(request, path, template_name='categories/category_detail.html', extra_context={}):
path_items = path.strip('/').split('/')
if len(path_items) >= 2:
category = get_object_or_404(
Category,
slug__iexact=path_items[-1],
level=len(path_items) - 1,
parent__slug__iexact=path_items[-2])
else:
category = get_object_or_404(
Category,
slug__iexact=path_items[-1],
level=len(path_items) - 1)
templates = []
while path_items:
templates.append('categories/%s.html' % '_'.join(path_items))
path_items.pop()
templates.append(template_name)
context = RequestContext(request)
context.update({'category': category})
if extra_context:
context.update(extra_context)
return HttpResponse(select_template(templates).render(context)) |
In my project I ended up modifying the above view code due to another issue. Afterwards I tried re-installing django-compressor without any patch and this time it worked fine. The main changes were: context = RequestContext(request)
...
return HttpResponse(select_template(templates).render(context)) was changed to: context = {}
...
return HttpResponse(select_template(templates).render(context, request)) Not sure what are the ramifications of this but it inadvertently fixed my issue. |
Django 1.8.17, django-compressor-2.1 rcssmin-1.0.6 rjsmin-1.0.12 For one response I found, I'm getting I also had the issue with django-compressor 1.6. |
Got same error with django 1.10.5. Fix using
works for me. |
hi, can you open a pull request? |
Fixes error ValueError: dictionary update sequence element #0 has length 1; 2 is required from issue django-compressor#706
Fixes error ValueError: dictionary update sequence element #0 has length 1; 2 is required from issue django-compressor#706
Unfortunatelly this solution seems to have problem with django 1.8. #836 |
I investigated this, here are my findings:
so yeah, if anyone could help me reproducing this in django 1.10, that would help. |
Following up on @trawick's earlier comment, in my Django 1.11 project using django-compressor 2.2, I am still having this problem. Whereas he found that just using
|
if you could tell me how to reproduce this or even better, give me a repro case, that would be grand. or, actually, even better, create a failing test for this :) |
Here's the template code and traceback:
The following code appears to be trying to target Django 1.8 by checking for
Context.flatten()
, even though that method was introduced in Django 1.7, which is what I am using.django-compressor/compressor/base.py
Lines 342 to 347 in 7043dc9
Changing it from:
to:
seems to fix it for me.
The text was updated successfully, but these errors were encountered: