Skip to content

Add warning log for local flag evaluation cold start#452

Merged
dmarticus merged 5 commits intomasterfrom
dmarticus/fix-flag-cold-start
Mar 5, 2026
Merged

Add warning log for local flag evaluation cold start#452
dmarticus merged 5 commits intomasterfrom
dmarticus/fix-flag-cold-start

Conversation

@dmarticus
Copy link
Contributor

@dmarticus dmarticus commented Mar 4, 2026

Summary

  • When feature_enabled() is called with only_evaluate_locally=True before feature flag definitions have been fetched, the SDK silently returns None. 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) returned None because 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_api already logs when the fetch itself fails, but there was no log at the point where None is actually returned to the caller.

Test plan

  • All 671 existing tests pass
  • Warning only fires when self.feature_flags is falsy (not loaded yet)

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>
@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

posthog-python Compliance Report

Date: 2026-03-05 21:26:34 UTC
Duration: 159374ms

✅ All Tests Passed!

29/29 tests passed


Capture Tests

29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 518ms
Format Validation.Event Has Uuid 1507ms
Format Validation.Event Has Lib Properties 1507ms
Format Validation.Distinct Id Is String 1506ms
Format Validation.Token Is Present 1507ms
Format Validation.Custom Properties Preserved 1506ms
Format Validation.Event Has Timestamp 1507ms
Retry Behavior.Retries On 503 9519ms
Retry Behavior.Does Not Retry On 400 3504ms
Retry Behavior.Does Not Retry On 401 3509ms
Retry Behavior.Respects Retry After Header 9514ms
Retry Behavior.Implements Backoff 23529ms
Retry Behavior.Retries On 500 7504ms
Retry Behavior.Retries On 502 7513ms
Retry Behavior.Retries On 504 7512ms
Retry Behavior.Max Retries Respected 23528ms
Deduplication.Generates Unique Uuids 1497ms
Deduplication.Preserves Uuid On Retry 7514ms
Deduplication.Preserves Uuid And Timestamp On Retry 14513ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 7517ms
Deduplication.No Duplicate Events In Batch 1504ms
Deduplication.Different Events Have Different Uuids 1507ms
Compression.Sends Gzip When Enabled 1507ms
Batch Format.Uses Proper Batch Structure 1507ms
Batch Format.Flush With No Events Sends Nothing 1005ms
Batch Format.Multiple Events Batched Together 1505ms
Error Handling.Does Not Retry On 403 3509ms
Error Handling.Does Not Retry On 413 3507ms
Error Handling.Retries On 408 7514ms

Copy link

@sakce sakce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stamp away

Copy link

@gustavohstrassburger gustavohstrassburger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@dmarticus dmarticus merged commit a99c7d7 into master Mar 5, 2026
21 checks passed
@dmarticus dmarticus deleted the dmarticus/fix-flag-cold-start branch March 5, 2026 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants