feat: Bind segment values as query parameters#20
Merged
Conversation
Add an optional Binder on TranslateContext that promotes value-bearing literals to bound query parameters instead of inlining them, so no user value (notably a regex `%`) reaches a driver that substitutes parameters by %-formatting the query text. With no Binder the output is unchanged. beep boop
|
Minimum allowed coverage is Generated by 🐒 cobertura-action against 92b5049 |
emyller
approved these changes
Jul 2, 2026
emyller
left a comment
There was a problem hiding this comment.
I'm a bit upset the interface has to change — a fix is available but you need to opt-in to it. I think I understand the issue and wish we'd have one consistent way to parse, with binding, but can't recommend a better approach without a deeper investigation and a much likely wider blast radius.
Looks good enough to me. Not blocking.
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.
Contributes to Flagsmith/flagsmith#7939.
In this PR, we add an opt-in way to have the translator emit bound query parameters instead of inlining segment values as SQL literals:
Binderinterface. When provided toTranslateContext, value literals (string operands,INitems, regex patterns,PERCENTAGE_SPLITand:semversalts) are recorded and replaced with a placeholder; read them offbinder.paramsafter translation. When absent, output is identical to today.PyformatParamStyleemits%(name)s(clickhouse-driver / django-clickhouse-backend),ClickHouseServerParamStyleemits{name:String}(clickhouse-connect server-side binding).Binder(prefix=...)namespaces the minted names so several predicates can be merged into one query — e.g. aUNION ALLover segments — without theirp0,p1, … colliding.Only arbitrary text values are bound. Validated numerics, booleans, and the fixed hash constants stay inline: they can't carry a
%and aren't an injection vector, so every bound value is a string and the{name:String}annotation stays uniform.The public API keeps returning
str | Nonespecifically so every existing caller, the parity harness, and the assertion suite are untouched.