Expected Behavior
Create a dictionary with keys and values that are strings. I was able to do this correctly when I was doing NativeTemplate(...).render(...) so I would expect that the behavior would be the same if I used a NativeEnvironment(...).from_string(...).render(...).
Actual Behavior
I have some templates that create dictionaries. However, those tests error out because I expect to create a payload like {'apples': 'bananas'} but am instead creating {'apples: bananas'}.
I dug around and saw that preserve_quotes=False here, which was odd because I thought the behavior should be the same if I was creating an environment or using the spontaneous environment. But it turns out the spontaneous environment is the base Environment.
Template Code
>>> env = NativeEnvironment()
>>> env.from_string('{ "{{a}}": "{{b}}" }').render(a='apple', b='banana')
{'apple: banana'}
>>> NativeTemplate('{ "{{a}}": "{{b}}" }').render(a='apple', b='banana')
{'apple': 'banana'}
>>> NativeTemplate('').environment
<jinja2.environment.Environment object at 0x10a688cc0>
Full Traceback
No traceback because it doesn't throw an error, this is just not the expected behavior
Your Environment
- Python version: 3.6.6
- Jinja version: 2.10
How I'm currently working around it
env = Environment()
... # set up globals & filters
env.template_class = NativeTemplate
Expected Behavior
Create a dictionary with keys and values that are strings. I was able to do this correctly when I was doing
NativeTemplate(...).render(...)so I would expect that the behavior would be the same if I used aNativeEnvironment(...).from_string(...).render(...).Actual Behavior
I have some templates that create dictionaries. However, those tests error out because I expect to create a payload like
{'apples': 'bananas'}but am instead creating{'apples: bananas'}.I dug around and saw that
preserve_quotes=Falsehere, which was odd because I thought the behavior should be the same if I was creating an environment or using the spontaneous environment. But it turns out the spontaneous environment is the baseEnvironment.Template Code
>>> env = NativeEnvironment() >>> env.from_string('{ "{{a}}": "{{b}}" }').render(a='apple', b='banana') {'apple: banana'} >>> NativeTemplate('{ "{{a}}": "{{b}}" }').render(a='apple', b='banana') {'apple': 'banana'} >>> NativeTemplate('').environment <jinja2.environment.Environment object at 0x10a688cc0>Full Traceback
No traceback because it doesn't throw an error, this is just not the expected behavior
Your Environment
How I'm currently working around it