Skip to content

feat: Support $.flags context values in segment conditions - #261

Draft
khvn26 wants to merge 2 commits into
mainfrom
feat/flags-context-values
Draft

khvn26 wants to merge 2 commits into
mainfrom
feat/flags-context-values

Conversation

@khvn26

@khvn26 khvn26 commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Closes #245.

Changes

  • Environment flags evaluate segments. get_environment_flags() in local evaluation / offline mode no longer strips segments from the evaluation context (fix: get_environment_flags includes segments in evaluation context #179 added the stripping), so identity-less $.flags.<feature>.<enabled|value|variant> and $.environment.* conditions now apply to environment flags.
  • Lazy identity flags resolve $.flags dependencies. Flags.get_flag() evaluates against a trimmed context: just the queried feature and the segments that override it. That trimmed context leaves out the flags a $.flags condition reads, so those conditions never matched. Features overridden by a segment with a $.flags condition are now found once per environment refresh (build_flag_dependent_feature_names). For those features, get_flag() evaluates the full context and memoises every resulting flag. All other features keep the trimmed fast path.
    • Detection parses each condition property with jsonpath-rfc9535, the parser the engine uses, and follows the engine's rules: only $.-prefixed properties that compile are JSONPath. A property is treated as reading $.flags unless its first segment selects top-level keys by name and none of them is flags. Wildcards, filters and $.. count as possibly reading it, so a wrong guess only costs speed, never correctness. jsonpath-rfc9535 is now a direct dependency, with the same >=0.1.5,<1 range as the engine.
  • The engine dependency is already on ^11.1.1 (deps: update dependency flagsmith-flag-engine to v11.1.0 #252, deps: bump flagsmith-engine to 11.1.1 #259), which includes $.flags support (feat: Evaluate flags that depend on other flags flagsmith-engine#343).

Behaviour change

Environment flags can now pick up segment overrides from segments whose rules match without an identity, e.g. $.environment.name conditions or IS_NOT_SET on a trait. This is what #245 asks for, and it matches the get_evaluation_result semantics discussed in Flagsmith/flagsmith#6051. Note that remote /api/v1/flags may still return plain environment defaults.

Tests

  • test_get_environment_flags_omits_segments_from_evaluation_context becomes ..._includes_segments_....
  • End-to-end tests for $.flags / $.environment overrides on environment flags and identity flags. These include a dependency that is itself overridden for an identity.
  • Unit tests for $.flags property detection (dot/bracket/descendant forms, nested rules) and for full-context resolution and memoisation in lazy Flags.

Environment flags are now evaluated with segments, so identity-less
`$.flags` and `$.environment` conditions apply to them.

Lazily resolved identity flags overridden by a segment reading `$.flags`
are evaluated against the full context, so their dependencies resolve.

Closes #245
@khvn26
khvn26 requested a review from a team as a code owner October 16, 2026 17:18
@khvn26
khvn26 requested review from emyller and removed request for a team October 16, 2026 17:18
@khvn26
khvn26 marked this pull request as draft October 16, 2026 17:19
Replace the regex with the JSONPath parser the engine uses, mirroring
how the engine reads condition properties. A property is ruled out only
when its first segment selects top-level keys by name, none of them
`flags`, so ambiguous selectors fall back to full-context evaluation.
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.

Support $.flags context values in segment conditions

2 participants