fix: don't send $feature_flag_called from module-level get_feature_flag_payload - #794
Closed
posthog[bot] wants to merge 1 commit into
Closed
fix: don't send $feature_flag_called from module-level get_feature_flag_payload#794posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
…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
Contributor
posthog-python Compliance ReportDate: 2026-07-28 08:00:16 UTC ✅ All Tests Passed!111/111 tests passed Capture_V1 Tests✅ 94/94 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
Contributor
|
wontfix |
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.
💡 Motivation and Context
The sdk-specs
get-feature-flag-payloadcontract says a payload-only read must not emit$feature_flag_called:openspec/specs/get-feature-flag-payload/spec.md— Behavior Fixed links to docs #4, "Suppress flag-called tracking by default for payload-only reads in audited server SDKs"$feature_flag_calledshould be enqueued" (mirrored inacceptance/public/get-feature-flag-payload.feature)get_feature_flag_payload(..., send_feature_flag_events=False, ...)Client.get_feature_flag_payload()already complies — #391 flipped its default toFalse. That PR only touchedposthog/client.py, though, and the module-levelposthog.get_feature_flag_payload()wrapper keptsend_feature_flag_events: bool = Trueand forwards the value explicitly to_proxy(...), so it always overrode the client'sFalse.Net effect: the two documented entry points for the same API disagreed.
The same default also tripped the client's own "
send_feature_flag_eventsis deprecated inget_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, andget_feature_flag_resultalready match between the two surfaces.Callers using the module-level
posthog.get_feature_flag_payload()stop getting$feature_flag_calledevents for payload lookups. If they were relying on that for exposure tracking, their exposure counts will drop. Mitigations: the parameter still exists, sosend_feature_flag_events=Truerestores the old behavior; and the spec/SDK direction is to useget_feature_flag()(orevaluate_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.pycovering the forwarded default and the explicit opt-in. Rantest_module.py,test_feature_flags.py,test_evaluate_flags.py,test_feature_flag_result.py,ruff format --check,ruff check, andcheck_public_api.py— all pass. No manual/integration testing beyond the test suite.📝 Checklist
If releasing new changes
sampo addto generate a changeset file — hand-written at.sampo/changesets/module-level-flag-payload-no-events.md(thesampoCLI 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
Applicabilityisbothorserver(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 Codegeneral-purposeagents 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 nodefault_valueparameter, which the recently-updatedis-feature-enabledspec makes a SHALL — additive and zero-risk, but the method is deprecated in favour ofevaluate_flags(), so where the parameter belongs is a judgement call; andflush()waits outflush_intervalinstead of bypassing it, which theflushspec 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