Fix feature flag 401 errors causing HTTP request storm#422
Merged
dustinbyrne merged 2 commits intoPostHog:masterfrom Feb 4, 2026
Merged
Fix feature flag 401 errors causing HTTP request storm#422dustinbyrne merged 2 commits intoPostHog:masterfrom
dustinbyrne merged 2 commits intoPostHog:masterfrom
Conversation
Set feature_flags = [] on 401 error to prevent repeated requests.
Contributor
Additional Comments (1)
The 402 error handler clears the Prompt To Fix With AIThis is a comment left during a code review.
Path: posthog/client.py
Line: 1338:1345
Comment:
`flag_cache` not cleared on 401 error
The 402 error handler clears the `flag_cache` (lines 1356-1357), but the 401 handler doesn't. For consistency and to ensure no stale cached evaluations remain, the flag cache should also be cleared here.
```suggestion
self.feature_flags = []
self.group_type_mapping = {}
self.cohorts = {}
# Clear flag cache when unauthorized
if self.flag_cache:
self.flag_cache.clear()
if self.debug:
```
How can I resolve this? If you propose a fix, please make it concise. |
dustinbyrne
approved these changes
Feb 4, 2026
Contributor
dustinbyrne
left a comment
There was a problem hiding this comment.
Thanks @GabiGrin! This looks great.
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_flags = []on 401 error to prevent repeated HTTP requestsFixes #421