Repository navigation
fix: take only module-level TEMPLATES as Django settings - #186
Merged
Merged
Conversation
…ocessor A TEMPLATES bound in a function, called or not, or in a class configures nothing; a function reading, mutating or rebinding the module's TEMPLATES leaves the activation uncertain; a local TEMPLATES beside module settings changes nothing.
request_processor walked every node of every module and counted any assignment to TEMPLATES, so a function-local or class-level assignment activated the request context processor. It now walks the modules with their scope tables: an assignment counts only at module scope, and a mention counts only when the name resolves to the module's binding, or to nothing, as a star import gives. ScopeTable.scope_for accepts a lambda, whose scope the builder already records.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #184.
Summary
request_processorwalked every node of every module and counted anyTEMPLATES = […]as Django settings, so an assignment inside a function, called or not, or a class attribute activated therequestcontext processor and upgraded a template filter finding to exploitable.ScopeAnalysis, already computed): an assignment counts only at module scope, and a mention counts only when the name resolves to the module's binding, or to nothing, which a star import gives. A function-localTEMPLATESis another name: it neither activates nor invalidates. A function that reads, mutates or rebinds (global) the module'sTEMPLATESstill leaves the activation uncertain, as before.ScopeTable.scope_fornow accepts a lambda, whose scope the builder already recorded; the walk needs it to enter every scope the builder knows.Verification
TEMPLATESactivated the processor, and a localTEMPLATESbeside module settings disabled it.tests/test_settings_scope.py: 9 passed; the request-processor and docs tests pass. Full suite (regression excluded in the worktree): all passed.ruff checkandmypypass.