jazzband / jazzband/django-floppyforms
Crash when rendering inclusion_tag with takes_context with multiple context processors
- Dominant language
- Python
- Stars
- 836
- Forks
- 150
- PR merge metrics
- No merged PRs in 30d
Description
I have an inclusion tag that looks something like this:
``` python
@register.inclusion_tag("template.html", takes_context=True)
def tag(context, variable):
context.update({'variable': variable})
return context
```
When rendering it I get the following stacktrace deep into floppyforms:
`ValueError: dictionary update sequence element #0 has length 6; 2 is required`
...because the context that gets sent in via takes_context is a list of dictionaries, not a dictionary. I think it's because that each context_processor adds one dictionary and that Django transparently handles that normally.
Here's the full stacktrace: http://dpaste.com/2FWD49D
It does not happen in floppyforms 1.3.0, but happens in 1.4.1. I think it might have something to do with this commit: https://github.com/gregmuellegger/django-floppyforms/commit/d591b12350af4b734cbcedd6c9becd330204268e
A workaround is to apply flatten_contexts to the inclusion tag:
``` python
@register.inclusion_tag("template.html", takes_context=True)
def tag(context, variable):
from floppyforms.compat import flatten_contexts
context = flatten_contexts(context)
context.update({'variable': variable})
return context
```
Sorry that I don't have time to write a proper testcase right now.
Contributor guide
Research direction
Start with the context-handling path implicated by commit d591b12350af4b734cbcedd6c9becd330204268e and inspect floppyforms.compat.flatten_contexts. Reproduce the inclusion_tag case with takes_context=True and multiple context processors, then add regression coverage showing that the tag receives a usable context and no longer raises the reported ValueError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, python
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100