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

Use a separate Jinja env per extension #1658

Merged
merged 1 commit into from
Aug 19, 2023

Conversation

andreasgerstmayr
Copy link
Contributor

Hi, I updated my two Fava extensions to load the CSS via

<style type="text/css">{% include "style.css" %}</style>

(possible since #1643)

However, I noticed that whenever I load extension A first, extension B gets the wrong stylesheet, and vice-versa. Turns out Jinja's Environment caches templates by name (https://github.com/pallets/jinja/blob/86f28a9df0a97a3d3bfa3785b082651e2a8e994d/src/jinja2/environment.py#L958) and therefore the style.css file of the extension which was loaded first gets in the cache.

I've updated the code to use a (overlay-)Environment per extension, which resolves this issue.

andreasgerstmayr added a commit to andreasgerstmayr/fava-portfolio-returns that referenced this pull request Aug 12, 2023
Jinja Environments cache templates by name, therefore we cannot use
the same environment across extensions.

Signed-off-by: Andreas Gerstmayr <[email protected]>
Copy link
Member

@yagebu yagebu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I've refactored this a bit to use a cached_property on the extension.

@yagebu yagebu merged commit 3e10d5a into beancount:main Aug 19, 2023
16 checks passed
@andreasgerstmayr
Copy link
Contributor Author

Thanks for the review & merging :)

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

Successfully merging this pull request may close these issues.

2 participants