Skip to content

fix: Return empty prerequisites for a flag that fails to evaluate in all_flags_state - #483

Open
jsonbailey wants to merge 2 commits into
mainfrom
jb/fix-sync-all-flags-state
Open

fix: Return empty prerequisites for a flag that fails to evaluate in all_flags_state#483
jsonbailey wants to merge 2 commits into
mainfrom
jb/fix-sync-all-flags-state

Conversation

@jsonbailey

@jsonbailey jsonbailey commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Summary

all_flags_state read result.prerequisites unconditionally even when a per-flag evaluation raised. The except branch set only detail, leaving result unbound (or holding a previous flag's value), so:

  • the first flag raising → UnboundLocalError that aborts the entire state payload;
  • a later flag raising → that flag silently inherits the previous flag's prerequisites.

Evaluator.evaluate() only catches its own EvaluationException; any other exception from malformed flag data propagates and reaches this path, so the except is genuinely reachable (rare, but real).

Fix

Bind prerequisites in both eval branches (success → result.prerequisites, error → []) so an evaluation error degrades only that flag. Adds a regression test (bad-first / good / bad-last) asserting no UnboundLocalError and that a failed flag does not inherit a neighbor's prerequisites.

This mirrors the same fix in the new async client (AsyncLDClient.all_flags_state).

Draft — surfaced during the async SDK review; no Jira ticket.


Note

Low Risk
Small, localized change to error handling in all_flags_state with a targeted regression test; no auth or data-path changes.

Overview
Fixes per-flag evaluation failures in all_flags_state so they no longer break the whole payload or leak another flag’s prerequisite metadata.

LDClient.all_flags_state now sets prerequisites in both the success path (result.prerequisites) and the error path ([]), instead of always reading result.prerequisites after the try/except. That avoids UnboundLocalError when the first flag raises and stops a later failed flag from inheriting a neighbor’s prerequisites.

Adds a regression test with bad-first / good / bad-last flag ordering to assert the call completes and failed flags omit prerequisites while a successful flag keeps its own.

Reviewed by Cursor Bugbot for commit 4f10055. Bugbot is set up for automated code reviews on this repo. Configure here.

…rror

all_flags_state read result.prerequisites unconditionally even when a per-flag
evaluation raised. The except branch set only detail, leaving result unbound (or
holding a previous flag's value), so the first flag raising caused an
UnboundLocalError that aborted the whole payload, and a later flag raising made
that flag inherit the previous flag's prerequisites. Evaluator.evaluate() only
catches its own EvaluationException, so any other exception from malformed flag
data reaches this path. Bind prerequisites in both eval branches (success ->
result.prerequisites, error -> []) so an error degrades only that flag. Mirrors
the same fix in the new async client.
@jsonbailey jsonbailey changed the title fix: Degrade only the failing flag in all_flags_state on evaluation error fix: Return empty prerequisites for a flag that fails to evaluate in all_flags_state Aug 6, 2026
@jsonbailey
jsonbailey marked this pull request as ready for review August 6, 2026 22:47
@jsonbailey
jsonbailey requested a review from a team as a code owner August 6, 2026 22:47
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.

1 participant