fix: preserve sessions across trigger impersonation - #90
Open
z125316840-code wants to merge 1 commit into
Open
Conversation
z125316840-code
marked this pull request as ready for review
July 30, 2026 05:53
Contributor
Confidence Score: 5/5The PR appears safe to merge. The scoped impersonation restores session identity and request-local state on both normal and exceptional exits, and no concrete changed-code failure was identified. Reviews (1): Last reviewed commit: "fix: preserve sessions across trigger im..." | Re-trigger Greptile |
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.
What changed
frappe.set_user(...)/ username-only restoration with a scoped_as_usercontext managerform_dictWhy
DocType Event triggers evaluate their condition synchronously in the request that saves or submits a document.
frappe.set_user()resets more thansession.user: it also replacessession.sid,session.data,form_dict, and permission/template caches. The previousfinally: frappe.set_user(original_user)restored the username but assigned the username as the SID, so the next browser request was treated as an expired session.Impact
Users who submit a document that dispatches a Flow trigger keep their authenticated browser session. The trigger still runs as its configured
run_asuser, falling back to the trigger owner, and the original request identity and context are restored even when trigger evaluation or execution raises.Validation
ruff check flow/triggers/triggers.py flow/tests/test_ai_triggers.pyruff format --check flow/triggers/triggers.py flow/tests/test_ai_triggers.pygit diff --checkA full Frappe integration run is left to the repository CI because this checkout does not contain a local Bench test site.