Repository navigation
Conversation
Locally evaluated flags in get_feature_flag(), feature_enabled() and get_feature_flag_result() sent $feature_flag_called without $feature_flag_id or $feature_flag_version, because both were read only from remote /flags metadata. Read them from the local flag definition that produced the value. evaluate_flags() already sent the id for local flags but dropped the definition's version; send it too.
Contributor
posthog-python Compliance ReportDate: 2026-10-29T15:20:18.463590+00:00 ✅ All Tests Passed!121/121 tests passed Capture_V1 Tests✅ 95/95 tests passed View Details
Capture_Ai Tests✅ 5/5 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
Feature_Flags_Local_Evaluation Tests✅ 4/4 tests passed View Details
|
andehen
added a commit
that referenced
this pull request
Oct 30, 2026
Typed details of a locally evaluated flag left the flag version out of flag_metadata. The local flag definition carries the version, but the evaluate_flags() snapshot record set it to None. The record now takes the version from the definition, and the details add it to flag_metadata when it is present. The record change is the same one #1149 makes, so $feature_flag_called for a snapshot read of a locally evaluated flag also carries $feature_flag_version.
This branch has not been deployed
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
$feature_flag_calledevents for locally evaluated flags had no$feature_flag_idand no$feature_flag_version._capture_feature_flag_calledread both only from the remote/flagsresponse metadata (flag_details.metadata), andflag_detailsisNonewhen the value came from local evaluation. This affectedget_feature_flag(),feature_enabled()andget_feature_flag_result(), and theget_feature_flag_payload(..., send_feature_flag_events=True)path that goes through the same code.The single-flag path now passes the
idandversionof the local flag definition into_capture_feature_flag_called. It reads the definition from the same definitions snapshot that produced the value, instead of re-readingfeature_flags_by_key.has_experimentnow also comes from that snapshot.evaluate_flags()already set$feature_flag_idfor locally evaluated flags, but always setversion=Nonebecause of a comment saying local definitions do not carry a version. The local evaluation definitions do includeversion, so the snapshot record now takes it from the definition.The async client does not evaluate locally, so it does not change.
💚 How did you test it?
TestCaptureCalls.test_locally_evaluated_flag_called_event_carries_definition_id_and_versioninposthog/test/test_feature_flags.py, parametrized overget_feature_flag,feature_enabledandget_feature_flag_result. A local definition withid4211 andversion7 must produce an event with both. All 3 fail onmain(KeyError: '$feature_flag_id').TestEvaluateFlagsLocalFlagIdentity.test_flag_called_event_carries_definition_id_and_versioninposthog/test/test_evaluate_flags.pycovers the same forevaluate_flags(), and checks that a definition withoutversionsends no$feature_flag_version. It fails onmain(KeyError: '$feature_flag_version').test_feature_flags.py,test_feature_flag_result.pyandtest_feature_flag_called_minimization.pynow include$feature_flag_id.$feature_flag_idwas already in the minimal-event allowlist.pytest posthog/test: 5829 passed, 25 skipped, 3 failed. The 3 failures are the forked-child tests intest_metrics_autocapture.py. They fail the same way on a cleanmaincheckout in a full run and pass when that file runs alone.📝 Checklist
If releasing new changes
.sampo/changesets/local-flag-called-id-version.md(pypi/posthog: patch).🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Claude Code wrote the change and the tests for the PR author, who directed the work. It found every path that sends
$feature_flag_calledfor a locally evaluated flag, then wrote tests that fail onmainbefore it made the fix. It passes the local id and version as explicit keyword arguments rather than building a syntheticFeatureFlag, so the remote metadata handling stays the same.🤖 Generated with Claude Code