Skip to content

Commit a99c7d7

Browse files
dmarticusclaude
andauthored
Add warning log for local flag evaluation cold start (#452)
* Add warning log when local flag evaluation called before flags loaded When feature_enabled() is called with only_evaluate_locally=True before flag definitions are fetched, the SDK silently returns None. This adds a warning log so users can diagnose the issue immediately. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Move cold start warning to only fire for only_evaluate_locally=True The warning was in _locally_evaluate_flag which runs for all flag evaluations, including those that fall back to server-side evaluation. Move it to the caller where only_evaluate_locally is known, so it only fires when the caller explicitly opted out of the server fallback. * Narrow cold start warning to only fire when flags were never fetched Use `is None` instead of `not` to avoid firing when flags are loaded but empty (401, 402, no personal_api_key), which already have their own specific error logs. * add changeset --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b206669 commit a99c7d7

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
pypi/posthog: patch
3+
---
4+
5+
Add warning log for local flag evaluation cold start

posthog/client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,13 @@ def _get_feature_flag_result(
16201620
self.flag_cache.set_cached_flag(
16211621
distinct_id, key, flag_result, self.flag_definition_version
16221622
)
1623-
elif not only_evaluate_locally:
1623+
elif only_evaluate_locally:
1624+
if self.feature_flags is None:
1625+
self.log.warning(
1626+
"[FEATURE FLAGS] Local evaluation called but feature flag definitions are not loaded yet. "
1627+
"Returning None. You can call load_feature_flags() to load flags explicitly."
1628+
)
1629+
else:
16241630
try:
16251631
flag_details, request_id, evaluated_at, errors_while_computing = (
16261632
self._get_feature_flag_details_from_server(

0 commit comments

Comments
 (0)