Skip to content

fix(tests): make segment rule and condition ordering deterministic - #8454

Merged
matthewelwell merged 3 commits into
mainfrom
fix/deterministic-segment-ordering-in-tests
Sep 4, 2026
Merged

fix(tests): make segment rule and condition ordering deterministic#8454
matthewelwell merged 3 commits into
mainfrom
fix/deterministic-segment-ordering-in-tests

Conversation

@matthewelwell

@matthewelwell matthewelwell commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Add settings to make segment ordering deterministic in the tests. Without this, downstream issues arise when using other database engines (e.g. MySQL, and Oracle)

SegmentRule and Condition use ConfiguredOrderManager, which only adds
`.order_by("id")` when the explicit-ordering settings are enabled. They
default to off, so in tests the queryset carries no ordering at all and
rows come back in whatever order the database happens to return.

Several tests depend on that order — the LaunchDarkly `large_segments`
snapshots compare serialised `rules_data`, so any reordering of rules or
conditions changes the output. They pass today because Postgres happens to
return rows in insertion order for these queries, not because anything
guarantees it. That is latent flakiness: nothing stops a plan change, an
update, or autovacuum altering it.

Enable both settings for tests so the ordering the code implicitly expects
is the ordering it gets. This also makes the same suites deterministic on
MySQL and Oracle, which is how it was found — Flagsmith/flagsmith-ee#224.

Both derived names are set rather than the
SEGMENT_RULES_CONDITIONS_EXPLICIT_ORDERING_ENABLED parent, because common.py
resolves the derived settings at import time, so setting only the parent in
test.py has no effect. For the same reason this cannot be done per test:
ConfiguredOrderManager reads the value when the manager is constructed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Sep 3, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated
docs Ready Ready Preview Sep 4, 2026 8:21am UTC
2 Skipped Deployments
Project Deployment Actions Updated
flagsmith-frontend-preview Ignored Ignored Preview Sep 4, 2026 8:21am UTC
flagsmith-frontend-staging Ignored Ignored Preview Sep 4, 2026 8:21am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Sep 3, 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: fbcbd315-76de-4152-b97a-752aff4f96d9

📥 Commits

Reviewing files that changed from the base of the PR and between 4a8a84a and 3ce2aee.

📒 Files selected for processing (1)
  • api/app/settings/test.py

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


📝 Walkthrough

Walkthrough

The test settings enable SEGMENT_CONDITIONS_EXPLICIT_ORDERING_ENABLED and SEGMENT_RULES_EXPLICIT_ORDERING_ENABLED. Both settings are set to True, so tests use explicit ordering instead of database return order.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Merge Risk: ⚪ Minimal · up to 744ff

This change makes segment-rule and condition ordering deterministic in tests, reducing database-specific snapshot instability without changing production behavior. No merge-blocking risk remains.


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.

@github-actions github-actions Bot added api Issue related to the REST API fix labels Sep 3, 2026
@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.81%. Comparing base (72bb92f) to head (744fff3).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8454      +/-   ##
==========================================
- Coverage   98.81%   98.81%   -0.01%     
==========================================
  Files        1621     1621              
  Lines       66297    66299       +2     
==========================================
+ Hits        65513    65514       +1     
- Misses        784      785       +1     

☔ 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 added fix and removed fix labels Sep 4, 2026
@matthewelwell
matthewelwell marked this pull request as ready for review September 4, 2026 08:01
@matthewelwell
matthewelwell requested a review from a team as a code owner September 4, 2026 08:01
@matthewelwell
matthewelwell requested review from emyller and removed request for a team September 4, 2026 08:01
@github-actions github-actions Bot removed the fix 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-e2e:pr-8454 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api-test:pr-8454 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-frontend:pr-8454 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-api:pr-8454 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-8454 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-8454 Finished ✅ Results

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

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor
✅ private-cloud · depot-ubuntu-latest-arm-16 — run #20157 (attempt 1)

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

passed  3 passed

Details

stats  3 tests across 3 suites
duration  37.9 seconds
commit  744fff3
info  🔄 Run: #20157 (attempt 1)

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

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  58.1 seconds
commit  744fff3
info  🔄 Run: #20157 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  42.4 seconds
commit  744fff3
info  🔄 Run: #20157 (attempt 1)

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

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  32 seconds
commit  744fff3
info  🔄 Run: #20157 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  48 seconds
commit  3ce2aee
info  🔄 Run: #20154 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  31.6 seconds
commit  3ce2aee
info  🔄 Run: #20154 (attempt 1)

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

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

passed  4 passed

Details

stats  4 tests across 4 suites
duration  39.7 seconds
commit  3ce2aee
info  🔄 Run: #20154 (attempt 1)

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

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

passed  3 passed

Details

stats  3 tests across 3 suites
duration  32.8 seconds
commit  3ce2aee
info  🔄 Run: #20154 (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

@github-actions github-actions Bot added fix and removed fix labels Sep 4, 2026
@matthewelwell
matthewelwell merged commit cc4c7b9 into main Sep 4, 2026
34 of 37 checks passed
@matthewelwell
matthewelwell deleted the fix/deterministic-segment-ordering-in-tests branch September 4, 2026 08:54
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