Skip to content

fix: don't send $feature_flag_called from module-level get_feature_flag_payload - #794

Closed
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/spec-payload-no-flag-called-events
Closed

fix: don't send $feature_flag_called from module-level get_feature_flag_payload#794
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/spec-payload-no-flag-called-events

Conversation

@posthog

@posthog posthog Bot commented Jul 28, 2026

Copy link
Copy Markdown

💡 Motivation and Context

The sdk-specs get-feature-flag-payload contract says a payload-only read must not emit $feature_flag_called:

Client.get_feature_flag_payload() already complies — #391 flipped its default to False. That PR only touched posthog/client.py, though, and the module-level posthog.get_feature_flag_payload() wrapper kept send_feature_flag_events: bool = True and forwards the value explicitly to _proxy(...), so it always overrode the client's False.

Net effect: the two documented entry points for the same API disagreed.

client.get_feature_flag_payload("checkout", "u1")   # no $feature_flag_called  ✅
posthog.get_feature_flag_payload("checkout", "u1")  # emits $feature_flag_called  ❌

The same default also tripped the client's own "send_feature_flag_events is deprecated in get_feature_flag_payload()" warning on every module-level call — warning users about a value they never passed.

Change

One-line default flip on the module-level wrapper (plus the docstring, the public API snapshot, and tests). No change to Client, and no change to any other flag API — feature_enabled, get_feature_flag, and get_feature_flag_result already match between the two surfaces.

⚠️ Behavior change

Callers using the module-level posthog.get_feature_flag_payload() stop getting $feature_flag_called events for payload lookups. If they were relying on that for exposure tracking, their exposure counts will drop. Mitigations: the parameter still exists, so send_feature_flag_events=True restores the old behavior; and the spec/SDK direction is to use get_feature_flag() (or evaluate_flags()) when you want exposures. This brings the module-level surface in line with the client method that has already behaved this way since #391.

💚 How did you test it?

Added two tests in posthog/test/test_module.py covering the forwarded default and the explicit opt-in. Ran test_module.py, test_feature_flags.py, test_evaluate_flags.py, test_feature_flag_result.py, ruff format --check, ruff check, and check_public_api.py — all pass. No manual/integration testing beyond the test suite.

📝 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. — behavior change, see above; changeset added.

If releasing new changes

  • Ran sampo add to generate a changeset file — hand-written at .sampo/changesets/module-level-flag-payload-no-events.md (the sampo CLI isn't available in this environment); please sanity-check the format.

🤖 Agent context

Autonomy: Fully autonomous

Opened by the SDK Spec Compliance Enforcer loop, which audits posthog-python against the contracts in PostHog/sdk-specs. This run checked the ~21 spec capabilities whose Applicability is both or server (capture, identify, alias, group-identify, before-send-hook, the six feature-flag public APIs, local-feature-flag-evaluator, flag-definition-loader, feature-flag-called-tracker, http-client, event-batcher, retry-queue, flush, shutdown, tracing-headers), using parallel read-only sub-agents (Claude Code general-purpose agents with Read/Grep/Bash) and verifying candidate findings by running the SDK locally.

Several other candidate divergences turned up. This one was chosen because it is unambiguous (the spec names the exact Python signature), the fix is one line, and it is plainly an incomplete-fix regression rather than a design question. Notable runners-up left for humans: feature_enabled() has no default_value parameter, which the recently-updated is-feature-enabled spec makes a SHALL — additive and zero-risk, but the method is deprecated in favour of evaluate_flags(), so where the parameter belongs is a judgement call; and flush() waits out flush_interval instead of bypassing it, which the flush spec forbids but which needs a consumer wake-signal rather than a one-liner.

Agent-authored — requires human review; not self-merged.


Created with PostHog Code

…ag_payload

`Client.get_feature_flag_payload()` defaults `send_feature_flag_events` to
`False`, but the module-level `posthog.get_feature_flag_payload()` wrapper
still defaulted it to `True` and forwarded the value explicitly, so the
client-side default was always overridden.

The sdk-specs `get-feature-flag-payload` contract requires payload-only reads
not to emit `$feature_flag_called`, and names `send_feature_flag_events=False`
in the canonical Python signature.

Align the module-level default with the client method.

Generated-By: PostHog Code
Task-Id: 213ed5a0-6911-4256-a84f-c1fe8eb63de7
@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

posthog-python Compliance Report

Date: 2026-07-28 08:00:16 UTC
Duration: 338824ms

✅ All Tests Passed!

111/111 tests passed


Capture_V1 Tests

94/94 tests passed

View Details
Test Status Duration
Endpoint And Method.Targets V1 Endpoint 517ms
Endpoint And Method.Does Not Use Legacy Endpoints 1008ms
Required Headers.Has Authorization Bearer Header 1008ms
Required Headers.Has Content Type Json 1009ms
Required Headers.Has Posthog Sdk Info Format 1009ms
Required Headers.Has Posthog Attempt Header 1008ms
Required Headers.Has Posthog Request Id 1008ms
Required Headers.Has Posthog Request Timestamp 1008ms
Required Headers.Has User Agent 1009ms
Body Format.Body Has Created At And Batch 1008ms
Body Format.No Api Key In Body 1008ms
Body Format.No Sent At In Body 1008ms
Event Format.Event Has Required Root Fields 1009ms
Event Format.Event Uuid Is Valid 1007ms
Event Format.Event Timestamp Is Rfc3339 1009ms
Event Format.Distinct Id Is String 1008ms
Event Format.Distinct Id At Root Not Properties 1009ms
Event Format.Custom Properties Preserved 1008ms
Event Format.Set Properties Preserved 1008ms
Event Format.Set Once Properties Preserved 1008ms
Event Format.Groups Properties Preserved 1009ms
Event Format.Sdk Generates Uuid If Not Provided 1008ms
Event Format.Event Has Required Root Fields Batch 1012ms
Event Format.Event Uuid Is Valid Batch 1013ms
Event Format.Event Timestamp Is Rfc3339 Batch 1012ms
Event Format.Distinct Id Is String Batch 1012ms
Event Format.Distinct Id At Root Not Properties Batch 1012ms
Event Format.Custom Properties Preserved Batch 1012ms
Event Format.Set Properties Preserved Batch 1012ms
Event Format.Set Once Properties Preserved Batch 1013ms
Event Format.Groups Properties Preserved Batch 1012ms
Event Format.Sdk Generates Uuid If Not Provided Batch 1012ms
Batch Behavior.Multiple Events In Single Batch 1507ms
Batch Behavior.Batch Envelope Smoke 1013ms
Batch Behavior.Flush With No Events Sends Nothing 1004ms
Batch Behavior.Flush At Triggers Batch 1508ms
Batch Behavior.Created At Reflects Batch Creation Time 1011ms
Deduplication.Generates Unique Uuids 1507ms
Deduplication.Different Events Same Content Different Uuids 1507ms
Deduplication.Preserves Uuid On Retry 7515ms
Deduplication.Preserves Timestamp On Retry 7511ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 7507ms
Deduplication.No Duplicate Events In Batch 1508ms
Header Behavior On Retry.Attempt Header Starts At One 1008ms
Header Behavior On Retry.Attempt Header Increments On Retry 14523ms
Header Behavior On Retry.Request Id Preserved On Retry 7508ms
Header Behavior On Retry.Different Requests Have Different Request Ids 3514ms
Header Behavior On Retry.Request Timestamp Changes On Retry 7514ms
Response Format Validation.Success Response Has Uuid Keyed Results 1005ms
Response Format Validation.Success Response Has Ok For Each Event 1506ms
Response Format Validation.Success No Retry After When All Ok 1507ms
Response Format Validation.Success Retry After Present When Retry Events 2510ms
Response Format Validation.Success No Retry After When Drop Only 1507ms
Response Format Validation.Response Echoes Request Id 1009ms
Retry Behavior.Retries On 408 7510ms
Retry Behavior.Retries On 500 7516ms
Retry Behavior.Retries On 503 9515ms
Retry Behavior.Retries On 504 7509ms
Retry Behavior.Retryable Errors Have Retry After 4510ms
Retry Behavior.Respects Retry After On Retryable Error 12510ms
Retry Behavior.Does Not Retry On 400 3511ms
Retry Behavior.Does Not Retry On 401 3507ms
Retry Behavior.Does Not Retry On 402 3507ms
Retry Behavior.Does Not Retry On 413 3507ms
Retry Behavior.Does Not Retry On 415 3507ms
Retry Behavior.Non Retryable Errors Have No Retry After 3508ms
Retry Behavior.Implements Backoff 23530ms
Retry Behavior.Max Retries Respected 23509ms
Partial Batch Handling.Handles 200 Full Success 3012ms
Partial Batch Handling.Handles 200 With All Ok 4508ms
Partial Batch Handling.Does Not Retry Dropped Events 4505ms
Partial Batch Handling.Does Not Retry Limited Events 4510ms
Partial Batch Handling.Prunes Ok Events On Partial Retry 7513ms
Partial Batch Handling.Prunes Dropped Events On Partial Retry 7512ms
Partial Batch Handling.Retries Only Retry Events From Partial 7511ms
Partial Batch Handling.Partial Retry Preserves Uuids 7511ms
Partial Batch Handling.Partial Retry Attempt Header Increments 7511ms
Partial Batch Handling.Partial Retry Request Id Preserved 7507ms
Partial Batch Handling.Respects Retry After On Partial 9516ms
Partial Batch Handling.Unknown Result Treated As Terminal 4505ms
Partial Batch Handling.Mixed Ok Drop Limited No Retry 4509ms
Compression.Sends Gzip Content Encoding 1007ms
Compression.No Content Encoding When Disabled 1008ms
Compression.Compressed Body Is Decompressible 1008ms
Error Handling.Does Not Retry On Unknown 4Xx 3509ms
Event Options.Cookieless Mode Override 1006ms
Event Options.Disable Skew Correction Override 1009ms
Event Options.Process Person Profile Override 1008ms
Event Options.Product Tour Id Override 1008ms
Event Options.Unset Options Omitted 1009ms
Event Options.Options Override In Batch 1012ms
Geoip And Historical Migration.Geoip Disable Injected Into Properties 1008ms
Geoip And Historical Migration.Historical Migration Set In Body 1008ms
Geoip And Historical Migration.Historical Migration Absent By Default 1009ms

Feature_Flags Tests

17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 1005ms
Request Payload.Flags Request Uses V2 Query Param 1007ms
Request Payload.Flags Request Hits Flags Path Not Decide 1006ms
Request Payload.Flags Request Omits Authorization Header 1006ms
Request Payload.Token In Flags Body Matches Init 1008ms
Request Payload.Groups Round Trip 1006ms
Request Payload.Groups Default To Empty Object 1006ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 1007ms
Request Payload.Disable Geoip Omitted Defaults To False 1006ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 1006ms
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 1010ms
Request Lifecycle.Mock Response Value Is Returned To Caller 1002ms
Retry Behavior.Retries Flags On 502 1006ms
Retry Behavior.Retries Flags On 504 1006ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 1509ms

@dustinbyrne

Copy link
Copy Markdown
Contributor

wontfix

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