Template caching does not take environment configuration into account
The template cache is not invalidated when the configuration of the environment changes.
See this minimal example
from jinja2 import Environment, FileSystemBytecodeCache, DictLoader
e = Environment(
bytecode_cache=FileSystemBytecodeCache(),
loader=DictLoader({'test': 'Test\n'}),
keep_trailing_newline=False
)
template = e.get_template("test")
print(repr(template.render()))
This will print: 'Test'
If i then change keep_trailing_newline=True and run the code again, the output is still 'Test'. I expected the output 'Test\n', because now the environment is configured to keep trailing newlines.
Manually clearing the cache and rerunning with keep_trailing_newline=True will then correctly output 'Test\n'.
Environment:
- Python version: 3.9.7
- Jinja version: 3.1.2
Not sure if this qualifies as a bug, but it is at least unexpected. If you decide that this needs to be fixed and if the issue is not critical, I would love to try and fix the issue myself.
See also #14, #153, #253, issues about caching from 2011 that are still open. Basically, the entire caching implementation probably needs to be redone, but that's a huge task so it's not going to get done any time soon (or late, given the age) unless someone steps up to really dig into it, understand the current system, and design and implement a new system.