Skip to content

fix: copy jinja_options per-instance to prevent shared mutable class default#6080

Closed
webdevdot wants to merge 2 commits into
pallets:mainfrom
webdevdot:fix/jinja-options-mutable-default
Closed

fix: copy jinja_options per-instance to prevent shared mutable class default#6080
webdevdot wants to merge 2 commits into
pallets:mainfrom
webdevdot:fix/jinja-options-mutable-default

Conversation

@webdevdot

Copy link
Copy Markdown

Summary

  • jinja_options: dict[str, t.Any] = {} at sansio/app.py:248 is a class-level mutable dict shared across all Flask instances and subclasses.
  • Mutations to jinja_options on one instance silently bleed into all other instances.
  • Fix: copy in __init__ with self.jinja_options = dict(self.__class__.jinja_options).

Test plan

  • Create two Flask instances; mutate app1.jinja_options; verify app2.jinja_options is unaffected.
  • Subclass Flask with custom jinja_options; verify instances of both the base and the subclass have independent dicts.

🤖 Generated with Claude Code

webcloudkey-projects and others added 2 commits July 4, 2026 04:53
…default

Class-level jinja_options = {} is shared across all Flask instances and
subclasses, so mutations on one instance silently affect all others.
Copy it in __init__ so each app gets its own dict.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@davidism davidism closed this Jul 4, 2026
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.

3 participants