refactor(permissions): return pypika criteria from query condition hooks - #509
Open
netchampfaris wants to merge 1 commit into
Open
netchampfaris wants to merge 1 commit into
netchampfaris wants to merge 1 commit into
Conversation
The permission_query_conditions hooks built their WHERE clauses by calling get_sql() on a pypika criterion through a local criterion_sql() helper. That inlined values using pypika's bare quote-doubling, which is unsafe on MariaDB (backslash is an escape character there). Frappe now accepts a pypika term directly from these hooks (frappe#40408) and renders values through the driver's escaping. Return the criteria as-is and drop the criterion_sql() helper.
UI Test Results✅ All passed — 37/37 tests passed in 1m 47s.
Results for commit fe48588. |
netchampfaris
marked this pull request as ready for review
June 29, 2026 22:07
Contributor
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 this does
Gameplan's
permission_query_conditionshooks build the WHERE clause that limits which rows a user can see (spaces, discussions, pages, comments, drafts, etc.).Until now each hook built a pypika criterion and then turned it into a SQL string itself, through a local
criterion_sql()helper that calledcriterion.get_sql(...). This PR returns the criterion directly and removes that helper.Why
criterion_sql()inlined values using pypika's own escaping, which only doubles single quotes. On MariaDB the backslash is also an escape character, so that escaping is not safe for arbitrary values.Frappe now accepts a pypika term straight from these hooks and renders the values through the database driver's escaping (the same path the query builder already uses for bound parameters). So the hooks no longer need to render SQL themselves — they just describe the condition and let the framework render it safely.
The result is less code and safer value handling, with no change to who can see what.
Depends on
Frappe PR frappe/frappe#40408 — adds pypika support to
permission_query_conditions. This PR cannot be merged or pass server tests until that change is available in the frappe branch Gameplan's CI installs.Warning
Gameplan CI installs frappe with
bench init(no--frappe-branch), which uses frappe's default stable branch. frappe#40408 targetsdevelop. The server tests here will stay red until the pypika support lands in the branch CI actually uses (either by backporting #40408 or by pointing CI at the branch that has it). Kept as a draft for that reason.no-docs