Skip to content

Commit 0b2b675

Browse files
committed
Add flag_missing error when requested flag is not in response
When the /flags API call succeeds but the requested flag is not in the response, set $feature_flag_error to "flag_missing". This helps distinguish between flags that don't exist vs other error conditions.
1 parent 9223531 commit 0b2b675

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

posthog/client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,8 @@ def _get_feature_flag_result(
15761576
)
15771577
if errors_while_computing:
15781578
feature_flag_error = "errors_while_computing_flags"
1579+
elif flag_details is None:
1580+
feature_flag_error = "flag_missing"
15791581

15801582
flag_result = FeatureFlagResult.from_flag_details(
15811583
flag_details, override_match_value

posthog/test/test_feature_flag_result.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,9 @@ def test_get_feature_flag_result_with_errors_while_computing_flags(
494494
def test_get_feature_flag_result_flag_not_in_response(
495495
self, patch_capture, patch_flags
496496
):
497-
"""Test that when a flag is not in the API response, we still capture the request_id.
497+
"""Test that when a flag is not in the API response, we capture flag_missing error.
498498
499-
This is the normal case when a flag doesn't exist or the user doesn't match
500-
any conditions - the flag simply won't be in the response.
499+
This happens when a flag doesn't exist or the user doesn't match any conditions.
501500
"""
502501
patch_flags.return_value = {
503502
"flags": {
@@ -526,6 +525,7 @@ def test_get_feature_flag_result_flag_not_in_response(
526525
"locally_evaluated": False,
527526
"$feature/missing-flag": None,
528527
"$feature_flag_request_id": "test-request-id-456",
528+
"$feature_flag_error": "flag_missing",
529529
},
530530
groups={},
531531
disable_geoip=None,

0 commit comments

Comments
 (0)