Skip to content

fix(Segment Membership): Percent sign in regex condition crashes segment count refresh#7944

Merged
khvn26 merged 3 commits into
mainfrom
worktree-fix+7939
Jul 2, 2026
Merged

fix(Segment Membership): Percent sign in regex condition crashes segment count refresh#7944
khvn26 merged 3 commits into
mainfrom
worktree-fix+7939

Conversation

@khvn26

@khvn26 khvn26 commented Jul 2, 2026

Copy link
Copy Markdown
Member

Thanks for submitting a PR! Please check the boxes below:

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Contributes to #7939.

In this PR, we bump flagsmith-sql-flag-engine to 0.2.0, and use its newly introduced query param capability to avoid clickhouse-driver crash with unescaped % characters in segment condition values.

How did you test this code?

Added ClickHouse-backed regression tests for both get_segment_members_page and compute_segment_counts_for_project using a segment whose regex pattern ([b%]ar) carries a literal % and still matches seeded identities.

…ent count refresh

A regex condition containing a `%` inlined a literal `%` into the
ClickHouse query text, which clickhouse-driver then misread as a
`query % params` placeholder, raising `TypeError: not enough arguments
for format string` before the query ran.

Bump flagsmith-sql-flag-engine to 0.2.0 and thread its `Binder` through
both segment-membership SQL builders so segment values — regex patterns
included — bind as query parameters instead of being inlined.

beep boop
@vercel

vercel Bot commented Jul 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Jul 2, 2026 6:37pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
flagsmith-frontend-preview Ignored Ignored Preview Jul 2, 2026 6:37pm
flagsmith-frontend-staging Ignored Ignored Preview Jul 2, 2026 6:37pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 5a578f02-6543-42ce-8155-490bc54d0472

📥 Commits

Reviewing files that changed from the base of the PR and between 31c9dc9 and 826f3b3.

⛔ Files ignored due to path filters (1)
  • api/uv.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • api/pyproject.toml
  • api/segment_membership/services.py
  • api/tests/unit/segment_membership/test_unit_segment_membership_services.py
  • docs/docs/deployment-self-hosting/observability/_events-catalogue.md

📝 Walkthrough

Walkthrough

This change bumps the flagsmith-sql-flag-engine dependency version, introduces Binder/PyformatParamStyle usage into TranslateContext construction within segment_membership services for building and executing parameterised ClickHouse queries, adds test coverage for regex patterns containing percent characters, and updates two log line-number references in the events catalogue documentation.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Changes

File Summary
api/pyproject.toml Bumped flagsmith-sql-flag-engine version constraint from >=0.1.3,<0.2.0 to >=0.2.0,<0.3.0.
api/segment_membership/services.py Added Binder/PyformatParamStyle imports; both query-building functions now construct a Binder and pass it into TranslateContext, merging binder.params into execution parameters.
api/tests/unit/segment_membership/test_unit_segment_membership_services.py Added REGEX import, a new fixture for percent-containing regex segments, and two ClickHouse tests validating member and count results.
docs/docs/deployment-self-hosting/observability/_events-catalogue.md Updated two logged source line-number references for services.py.

Sequence Diagram(s)

sequenceDiagram
  participant Service as compute_segment_counts_for_project/get_segment_members_page
  participant Binder as Binder(PyformatParamStyle)
  participant Context as TranslateContext
  participant Cursor as cursor

  Service->>Binder: create Binder(PyformatParamStyle())
  Service->>Context: TranslateContext(binder=Binder)
  Context-->>Service: translated predicate
  Service->>Service: merge binder.params with env_key/limit
  Service->>Cursor: execute(sql, **params, **binder.params)
Loading

Related issues: None provided.

Related PRs: None provided.

Suggested labels: dependencies, backend, tests

Suggested reviewers: None specified.

Poem

A binder hops in, params in tow,
Percent signs in regex, matched just so,
Counts and members line up in a row,
Docs nudge their numbers, line by line they grow,
A rabbit taps the query — off it goes! 🐇


Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added api Issue related to the REST API fix labels Jul 2, 2026
…e numbers

The services.py edits shifted the source lines of two existing structlog
events, so the generated events catalogue no longer matched. Regenerate it.

beep boop
@github-actions github-actions Bot added docs Documentation updates fix and removed fix docs Documentation updates labels Jul 2, 2026
Remove the explanatory block comments and regenerate the events
catalogue for the resulting line-number shift.

beep boop
@github-actions github-actions Bot added docs Documentation updates fix and removed fix docs Documentation updates labels Jul 2, 2026
@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.63%. Comparing base (cbc295a) to head (826f3b3).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7944   +/-   ##
=======================================
  Coverage   98.63%   98.63%           
=======================================
  Files        1497     1497           
  Lines       59151    59169   +18     
=======================================
+ Hits        58345    58363   +18     
  Misses        806      806           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@khvn26 khvn26 marked this pull request as ready for review July 2, 2026 18:46
@khvn26 khvn26 requested review from a team as code owners July 2, 2026 18:46
@khvn26 khvn26 requested review from emyller and removed request for a team July 2, 2026 18:46
@github-actions github-actions Bot added fix and removed fix labels Jul 2, 2026
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-e2e:pr-7944 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-frontend:pr-7944 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-api-test:pr-7944 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith:pr-7944 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-api:pr-7944 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-7944 Finished ✅ Results

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  4 passed

Details

stats  4 tests across 3 suites
duration  44.5 seconds
commit  826f3b3
info  🔄 Run: #18042 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  3 passed

Details

stats  3 tests across 3 suites
duration  35.9 seconds
commit  826f3b3
info  🔄 Run: #18042 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  7 passed

Details

stats  7 tests across 5 suites
duration  21.8 seconds
commit  826f3b3
info  🔄 Run: #18042 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  1 minute, 9 seconds
commit  826f3b3
info  🔄 Run: #18042 (attempt 1)

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Visual Regression

19 screenshots compared. See report for details.
View full report

@khvn26 khvn26 merged commit e77c851 into main Jul 2, 2026
53 checks passed
@khvn26 khvn26 deleted the worktree-fix+7939 branch July 2, 2026 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants