Add warning log for local flag evaluation cold start#452
Merged
Conversation
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>
Contributor
posthog-python Compliance ReportDate: 2026-03-05 21:26:34 UTC ✅ All Tests Passed!29/29 tests passed Capture Tests✅ 29/29 tests passed View Details
|
gustavohstrassburger
approved these changes
Mar 5, 2026
gustavohstrassburger
left a comment
There was a problem hiding this comment.
Both AI comments seems legit though.
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
feature_enabled()is called withonly_evaluate_locally=Truebefore feature flag definitions have been fetched, the SDK silently returnsNone. This adds a warning log so users can diagnose the issue immediately instead of debugging SDK internals.Context
Discovered when debugging a "cold start" issue in a Django shell on a production pod. The first call to
feature_enabled(..., only_evaluate_locally=True)returnedNonebecause the initial HTTP fetch of flag definitions hadn't completed (or failed silently). The second call worked fine because the poller had since fetched the flags.The existing error path in
_fetch_feature_flags_from_apialready logs when the fetch itself fails, but there was no log at the point whereNoneis actually returned to the caller.Test plan
self.feature_flagsis falsy (not loaded yet)