Skip to content

fix(translator): % Split without explicitly provided identity context translate to FALSE#16

Merged
khvn26 merged 5 commits into
mainfrom
fix/percentage-split-row-translation
Jun 30, 2026
Merged

fix(translator): % Split without explicitly provided identity context translate to FALSE#16
khvn26 merged 5 commits into
mainfrom
fix/percentage-split-row-translation

Conversation

@khvn26

@khvn26 khvn26 commented Jun 29, 2026

Copy link
Copy Markdown
Member

Contributes to Flagsmith/flagsmith#7911.

In this PR, we drops the eval-context identity guard for those three cases and emits the per-row hash. Trait-keyed splits are unchanged.

It intentionally diverges from flag_engine's single-eval "no identity → False" verdict for the identity-less context. That verdict is right for a single in-memory evaluation; it isn't for the SQL engine, whose whole job is to evaluate over identity rows where the key always exists. TranslateContext's docstring already states the identity field is ignored because values come from each row — this makes the percentage-split path honour that.

@khvn26 khvn26 requested a review from a team as a code owner June 29, 2026 18:24
@khvn26 khvn26 requested review from emyller and removed request for a team June 29, 2026 18:24

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the SQL flag engine translator to allow percentage splits to be translatable even when the evaluation context does not carry an identity. It removes the checks that previously collapsed these conditions to FALSE, allowing the engine to hash the per-row identity key or identifier instead. Unit tests have been updated to verify this new behavior. I have no feedback to provide as there are no review comments.

@khvn26 khvn26 force-pushed the fix/percentage-split-row-translation branch from 0e23b2e to 0b5fd4f Compare June 29, 2026 18:30
@github-actions

github-actions Bot commented Jun 29, 2026

Copy link
Copy Markdown

File Coverage Missing
All files 100%

Minimum allowed coverage is 100%

Generated by 🐒 cobertura-action against 0c7ec9a

@khvn26 khvn26 force-pushed the fix/percentage-split-row-translation branch from 0b5fd4f to 85f2412 Compare June 29, 2026 18:34
…t identity

A PERCENTAGE_SPLIT keyed on the identity (implicit `$.identity.key`,
`$.identity.key`, or `$.identity.identifier`) compiled to FALSE when the
evaluation context carried no identity. The translated predicate runs
per-row over IDENTITIES, where the identity-key and identifier columns are
always present, so it should hash the row column regardless of whether the
row-oriented context supplies an identity. The guard made row-oriented
callers (segment-membership counts/members) see every percentage-split
segment as empty.

Drop the eval-context identity guard for those three cases and emit the
per-row hash. Trait-keyed splits are unchanged.

This intentionally diverges from flag_engine's single-eval "no identity ->
False" for the identity-less context, which is correct for the row-oriented
SQL engine where every row is an identity; the one engine-test-data case
that exercises it (test_percentage_split__no_identity_key__should_match) is
added to the ClickHouse harness's _XFAIL_CASE_NAMES. The translator unit
tests assert the full emitted SQL.

beep boop
Claude-Session: https://claude.ai/code/session_01EgZ5iHpDASZzCapiHRxHLB
@khvn26 khvn26 force-pushed the fix/percentage-split-row-translation branch from 85f2412 to 6de406d Compare June 29, 2026 18:36

@emyller emyller left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I think neither the PR description, nor the patch within, make it clear what the real goal is, e.g. helping towards this.

we drops the eval-context identity guard for those three cases and emits the per-row hash

Please improve perception of why in better comments and tests, or let me know if you'd rather unblock other work first and need an approval.

Comment thread src/flagsmith_sql_flag_engine/translator.py Outdated
Comment thread tests/test_translator_unit.py Outdated
Comment thread tests/test_translator_unit.py Outdated
@khvn26 khvn26 changed the title fix(translator): Hash identity-key percentage splits without a context identity translate to FALSE fix(translator): % Split without explicitly provided identity context translate to FALSE Jun 29, 2026
@khvn26 khvn26 requested a review from emyller June 29, 2026 20:22
emyller
emyller previously approved these changes Jun 29, 2026

@emyller emyller left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests could still look less over-reaching, but not blocking.

Comment thread src/flagsmith_sql_flag_engine/translator.py Outdated
Comment thread tests/test_translator_unit.py Outdated
Co-authored-by: Matthew Elwell <mjelwell89@gmail.com>
@khvn26 khvn26 merged commit 78cbd1a into main Jun 30, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants