Skip to content

fix(segment_membership): preserve system traits when seeding identities into ClickHouse - #8458

Merged
gagantrivedi merged 3 commits into
mainfrom
fix/segment-membership-seed-system-traits
Sep 4, 2026
Merged

fix(segment_membership): preserve system traits when seeding identities into ClickHouse#8458
gagantrivedi merged 3 commits into
mainfrom
fix/segment-membership-seed-system-traits

Conversation

@gagantrivedi

@gagantrivedi gagantrivedi commented Sep 4, 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

seed_organisation_identities silently wiped cohort membership: its mapper read only identity_traits, and the seeded rows — stamped with the scan-start inserted_at — superseded older CDC-written rows (which carry cohort system_traits) at ReplacingMergeTree dedup. Any org that gained cohorts before its first seed, and any force re-seed of an org with cohorts, lost cohort membership in ClickHouse until each identity was next written through the CDC stream.

map_identity_document_to_clickhouse_row now merges system_traits over the flattened identity_traits (system value wins on key clash), matching the precedence used at flag evaluation and by edge-api's CDC path (Flagsmith/edge-api#707). A system_traits attribute stored as NULL counts as absent. The field is declared on flagsmith_schemas.dynamodb.Identity as of Flagsmith/flagsmith-common#271; this PR bumps flagsmith-common to 3.14.0 and reads it typed.

How did you test this code?

  • New unit cases in test_unit_segment_membership_mappers.py: system wins over a spoofed user trait (with Decimal coercion), system-traits-only documents, and NULL-stored system_traits.
  • New integration regression in test_segment_membership_clickhouse.py against real ClickHouse: a CDC-written row carrying a cohort trait is superseded by a re-seed and the surviving row still carries the cohort.
  • Full tests/unit/segment_membership/ (67 passed) and tests/integration/segment_membership/ (5 passed) suites, plus mypy.

@gagantrivedi
gagantrivedi requested a review from a team as a code owner September 4, 2026 05:34
@gagantrivedi
gagantrivedi requested review from matthewelwell and removed request for a team September 4, 2026 05:34
@vercel

vercel Bot commented Sep 4, 2026

Copy link
Copy Markdown

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

3 Skipped Deployments
Project Deployment Actions Updated
docs Ignored Ignored Preview Sep 4, 2026 7:37am UTC
flagsmith-frontend-preview Ignored Ignored Preview Sep 4, 2026 7:37am UTC
flagsmith-frontend-staging Ignored Ignored Preview Sep 4, 2026 7:37am UTC

Request Review

@github-actions github-actions Bot added the api Issue related to the REST API label Sep 4, 2026
@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Docker builds report

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

@github-actions github-actions Bot added the fix label Sep 4, 2026
@coderabbitai

coderabbitai Bot commented Sep 4, 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: Team

Run ID: 59c5befb-390d-44ab-813e-067098641f4e

📥 Commits

Reviewing files that changed from the base of the PR and between 054dca9 and 19d3a13.

📒 Files selected for processing (1)
  • api/segment_membership/mappers.py
💤 Files with no reviewable changes (1)
  • api/segment_membership/mappers.py

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

The identity mapper now reads optional system_traits from Dynamo identity documents. It coerces system trait values and merges them over user traits. Unit tests cover precedence, system-only traits, and NULL values. An integration test verifies that reseeding preserves regular and cohort traits in ClickHouse. The flagsmith-common dependency lower bound is raised to 3.14.0.

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

Merge Risk: ⚪ Minimal · up to 19d3a

The change preserves cohort system traits during identity reseeding and includes stated unit and integration coverage. No current merge-blocking risk is established.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Team

Run ID: 284bfba5-9849-460d-8526-8e83415328ab

📥 Commits

Reviewing files that changed from the base of the PR and between 4a8a84a and 7fd093c.

📒 Files selected for processing (3)
  • api/segment_membership/mappers.py
  • api/tests/integration/segment_membership/test_segment_membership_clickhouse.py
  • api/tests/unit/segment_membership/test_unit_segment_membership_mappers.py

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@codecov

codecov Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.81%. Comparing base (4a8a84a) to head (19d3a13).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8458   +/-   ##
=======================================
  Coverage   98.81%   98.81%           
=======================================
  Files        1621     1621           
  Lines       66138    66158   +20     
=======================================
+ Hits        65354    65374   +20     
  Misses        784      784           

☔ 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.

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor
✅ oss · depot-ubuntu-latest-16 — run #20152 (attempt 1)

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  35.6 seconds
commit  19d3a13
info  🔄 Run: #20152 (attempt 1)

🗂️ Previous results
✅ private-cloud · depot-ubuntu-latest-16 — run #20152 (attempt 1)

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  32.1 seconds
commit  19d3a13
info  🔄 Run: #20152 (attempt 1)

✅ private-cloud · depot-ubuntu-latest-arm-16 — run #20152 (attempt 1)

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  36.5 seconds
commit  19d3a13
info  🔄 Run: #20152 (attempt 1)

✅ oss · depot-ubuntu-latest-arm-16 — run #20152 (attempt 1)

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  44.4 seconds
commit  19d3a13
info  🔄 Run: #20152 (attempt 1)

✅ oss · depot-ubuntu-latest-arm-16 — run #20151 (attempt 1)

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  46.8 seconds
commit  054dca9
info  🔄 Run: #20151 (attempt 1)

✅ oss · depot-ubuntu-latest-16 — run #20151 (attempt 1)

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  42.3 seconds
commit  054dca9
info  🔄 Run: #20151 (attempt 1)

✅ private-cloud · depot-ubuntu-latest-16 — run #20151 (attempt 1)

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  31.8 seconds
commit  054dca9
info  🔄 Run: #20151 (attempt 1)

✅ private-cloud · depot-ubuntu-latest-arm-16 — run #20151 (attempt 1)

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

passed  3 passed

Details

stats  3 tests across 3 suites
duration  36.9 seconds
commit  054dca9
info  🔄 Run: #20151 (attempt 1)

❌ private-cloud · depot-ubuntu-latest-16 — run #20149 (attempt 1)

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

failed  3 failed
passed  1 passed

Details

stats  4 tests across 4 suites
duration  26 seconds
commit  7fd093c
info  📦 Artifacts: View test results and HTML report
🔄 Run: #20149 (attempt 1)

Failed tests

firefox › tests/change-request-test.pw.ts › Change Request Tests › Change requests can be created, approved, and published with four-eyes approval @enterprise
firefox › tests/roles-test.pw.ts › Roles Tests › Roles can be created with project and environment permissions @enterprise
firefox › tests/sso-test.pw.ts › SCIM Tests › SCIM configuration can be created, regenerated, and deleted @enterprise

✅ oss · depot-ubuntu-latest-arm-16 — run #20149 (attempt 1)

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  45.6 seconds
commit  7fd093c
info  🔄 Run: #20149 (attempt 1)

✅ oss · depot-ubuntu-latest-16 — run #20149 (attempt 1)

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  32.5 seconds
commit  7fd093c
info  🔄 Run: #20149 (attempt 1)

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Visual Regression

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

@gagantrivedi
gagantrivedi marked this pull request as ready for review September 4, 2026 07:22
@github-actions github-actions Bot added fix and removed fix labels Sep 4, 2026
@github-actions github-actions Bot added fix and removed fix labels Sep 4, 2026
@gagantrivedi
gagantrivedi removed the request for review from matthewelwell September 4, 2026 08:15
@gagantrivedi
gagantrivedi merged commit e6aea0f into main Sep 4, 2026
34 checks passed
@gagantrivedi
gagantrivedi deleted the fix/segment-membership-seed-system-traits branch September 4, 2026 08:16
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