feat: redirect from data script#619
Merged
surajshetty3416 merged 2 commits intoJun 3, 2026
Merged
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #619 +/- ##
===========================================
+ Coverage 58.41% 58.63% +0.21%
===========================================
Files 29 29
Lines 3239 3256 +17
===========================================
+ Hits 1892 1909 +17
Misses 1347 1347 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
surajshetty3416
approved these changes
Jun 3, 2026
Member
|
@pratikb64 Update docs as well? |
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.
Redirect visitors to a URL from a Data Script
What
Adds the ability to redirect a page visitor to any URL from within a page Data Script.
Why
Data scripts already run server-side on every render and can branch on the
session/user, but there was no way to send the visitor elsewhere. This closes that gap with a one-line helper.
How
redirect(location, http_status_code=302)helper into the pagedata script namespace. When called during an actual page render it sets
frappe.local.flags.redirect_locationand raisesfrappe.Redirect, which theFrappe website renderer turns into a real HTTP redirect — entirely
server-side
Security
get_page_datais split into a whitelisted wrapper (alwaysfor_render=False) and an internal_get_page_data(for_render=True)usedonly by the render path — so a client cannot trigger the redirect via the API.
page_data_scriptare now markedno_cache. A data script canbranch on the user/session, so without this a render for one user could be
cached and served to another, bypassing a conditional redirect (auth-bypass).
level as any data script); external URLs are intentionally allowed.
Tests
test_redirect_from_page_data_script: asserts the rendered response is a302 to the target URL, and that the editor's
get_page_data()call is ano-op returning empty data.