Skip to content

fix: no-op flag helpers on API errors#639

Open
marandaneto wants to merge 2 commits into
mainfrom
fix/noop-flag-api-errors
Open

fix: no-op flag helpers on API errors#639
marandaneto wants to merge 2 commits into
mainfrom
fix/noop-flag-api-errors

Conversation

@marandaneto
Copy link
Copy Markdown
Member

💡 Motivation and Context

The Python Client-only feature flag helpers should return default values instead of raising when /flags fails because the SDK is non-operational, for example due to an invalid non-empty project API key.

Changes:

  • Catch flag API exceptions in Client.get_flags_decision() and return an empty normalized flags response.
  • Cover the convenience helpers that depend on get_flags_decision() (get_feature_variants, get_feature_payloads, and get_feature_flags_and_payloads).
  • Add a Sampo changeset.

💚 How did you test it?

  • uv run pytest posthog/test/test_client.py -q

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran sampo add to generate a changeset file

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 31, 2026

posthog-python Compliance Report

Date: 2026-06-01 07:36:11 UTC
Duration: 176135ms

✅ All Tests Passed!

45/45 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 1508ms
Format Validation.Event Has Lib Properties 1507ms
Format Validation.Distinct Id Is String 1507ms
Format Validation.Token Is Present 1507ms
Format Validation.Custom Properties Preserved 1507ms
Format Validation.Event Has Timestamp 1507ms
Retry Behavior.Retries On 503 9519ms
Retry Behavior.Does Not Retry On 400 3506ms
Retry Behavior.Does Not Retry On 401 3508ms
Retry Behavior.Respects Retry After Header 9515ms
Retry Behavior.Implements Backoff 23530ms
Retry Behavior.Retries On 500 7506ms
Retry Behavior.Retries On 502 7513ms
Retry Behavior.Retries On 504 7512ms
Retry Behavior.Max Retries Respected 23519ms
Deduplication.Generates Unique Uuids 1509ms
Deduplication.Preserves Uuid On Retry 7516ms
Deduplication.Preserves Uuid And Timestamp On Retry 14521ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 7509ms
Deduplication.No Duplicate Events In Batch 1503ms
Deduplication.Different Events Have Different Uuids 1507ms
Compression.Sends Gzip When Enabled 1508ms
Batch Format.Uses Proper Batch Structure 1507ms
Batch Format.Flush With No Events Sends Nothing 1005ms
Batch Format.Multiple Events Batched Together 1506ms
Error Handling.Does Not Retry On 403 3507ms
Error Handling.Does Not Retry On 413 3508ms
Error Handling.Retries On 408 7516ms

Feature_Flags Tests

16/16 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 1003ms
Request Payload.Flags Request Uses V2 Query Param 1007ms
Request Payload.Flags Request Hits Flags Path Not Decide 1007ms
Request Payload.Flags Request Omits Authorization Header 1007ms
Request Payload.Token In Flags Body Matches Init 1007ms
Request Payload.Groups Round Trip 1007ms
Request Payload.Groups Default To Empty Object 1006ms
Request Payload.Person Properties Distinct Id Auto Populated When Caller Omits It 1006ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 1007ms
Request Payload.Disable Geoip Omitted Defaults To False 1007ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 1007ms
Request Lifecycle.No Flags Request On Init Alone 503ms
Request Lifecycle.No Flags Request On Normal Capture 1507ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 1011ms
Request Lifecycle.Mock Response Value Is Returned To Caller 1003ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 1509ms

@marandaneto marandaneto force-pushed the fix/noop-flag-api-errors branch 2 times, most recently from 32f6735 to 8ca7c5b Compare June 1, 2026 06:42
@marandaneto marandaneto marked this pull request as ready for review June 1, 2026 06:49
@marandaneto marandaneto requested a review from a team as a code owner June 1, 2026 06:49
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Jun 1, 2026

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
posthog/test/test_client.py:107-120
**Non-parameterized test for multiple helpers**

The test bundles four independent assertions in one method, so a failure in the first assertion (e.g. `get_flags_decision`) silences the remaining three. The codebase already uses both `@parameterized.expand` and `subTest` loops for exactly this scenario — see the `test_methods_handle_exceptions` test at line 2825 for a close parallel. Using `subTest` (or `@parameterized.expand`) would let all four helpers run independently and report individually, which is the team's stated preference for parameterised tests.

Reviews (1): Last reviewed commit: "fix: preserve flag error handling on fla..." | Re-trigger Greptile

Comment thread posthog/test/test_client.py Outdated
@marandaneto marandaneto force-pushed the fix/noop-flag-api-errors branch from 8ca7c5b to ac6b054 Compare June 1, 2026 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant