Skip to content
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

Crash when rendering inclusion_tag with takes_context with multiple context processors #153

Open
EmilStenstrom opened this issue Jun 22, 2015 · 2 comments

Comments

@EmilStenstrom
Copy link

I have an inclusion tag that looks something like this:

@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: d591b12

A workaround is to apply flatten_contexts to the inclusion tag:

@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.

gregmuellegger added a commit that referenced this issue Jun 22, 2015
@gregmuellegger
Copy link
Collaborator

Hi, thanks for the report. I added some tests in the branch issue/153 (9baf923) but the tests seem to pass for this.

Do you do anything differently than I do in the tests?

@EmilStenstrom
Copy link
Author

I'll have a look at the tests tomorrow and see if I can make them fail by adding more of my use case in there. I have an {% include "template.html" %} there and I think that context_processors might affect the how the context is returned. But I need to experiment a bit to get to a use case. Thanks for getting me started! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants