Skip to content

Commit a474f9c

Browse files
committed
Report combined errors when both errors_while_computing and flag_missing
When the server returns errorsWhileComputingFlags=true AND the requested flag is not in the response, report both conditions as a comma-separated string: "errors_while_computing_flags,flag_missing" This provides better debugging context when both conditions occur.
1 parent d9f380d commit a474f9c

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

posthog/client.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,10 +1590,13 @@ def _get_feature_flag_result(
15901590
disable_geoip,
15911591
)
15921592
)
1593+
errors = []
15931594
if errors_while_computing:
1594-
feature_flag_error = "errors_while_computing_flags"
1595-
elif flag_details is None:
1596-
feature_flag_error = "flag_missing"
1595+
errors.append("errors_while_computing_flags")
1596+
if flag_details is None:
1597+
errors.append("flag_missing")
1598+
if errors:
1599+
feature_flag_error = ",".join(errors)
15971600

15981601
flag_result = FeatureFlagResult.from_flag_details(
15991602
flag_details, override_match_value

posthog/test/test_feature_flag_result.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,42 @@ def test_get_feature_flag_result_flag_not_in_response(
544544
disable_geoip=None,
545545
)
546546

547+
@mock.patch("posthog.client.flags")
548+
@mock.patch.object(Client, "capture")
549+
def test_get_feature_flag_result_errors_computing_and_flag_missing(
550+
self, patch_capture, patch_flags
551+
):
552+
"""Test that both errors are reported when errorsWhileComputingFlags=true AND flag is missing.
553+
554+
This can happen when the server encounters errors computing flags AND the requested
555+
flag is not in the response. Both conditions should be reported for debugging.
556+
"""
557+
patch_flags.return_value = {
558+
"flags": {}, # Flag is missing
559+
"requestId": "test-request-id-999",
560+
"errorsWhileComputingFlags": True, # But errors also occurred
561+
}
562+
563+
flag_result = self.client.get_feature_flag_result(
564+
"missing-flag", "some-distinct-id"
565+
)
566+
567+
self.assertIsNone(flag_result)
568+
patch_capture.assert_called_with(
569+
"$feature_flag_called",
570+
distinct_id="some-distinct-id",
571+
properties={
572+
"$feature_flag": "missing-flag",
573+
"$feature_flag_response": None,
574+
"locally_evaluated": False,
575+
"$feature/missing-flag": None,
576+
"$feature_flag_request_id": "test-request-id-999",
577+
"$feature_flag_error": "errors_while_computing_flags,flag_missing",
578+
},
579+
groups={},
580+
disable_geoip=None,
581+
)
582+
547583
@mock.patch("posthog.client.flags")
548584
@mock.patch.object(Client, "capture")
549585
def test_get_feature_flag_result_unknown_error(self, patch_capture, patch_flags):

0 commit comments

Comments
 (0)