feat(flags): add default_value to feature_enabled() - #859
Closed
posthog[bot] wants to merge 2 commits into
Closed
Conversation
Bring `feature_enabled()` in line with the sdk-specs `is-feature-enabled` contract's hard SHALL: accept a caller-supplied boolean default and return it whenever the flag has no value (not loaded, failed request, or unknown key). A flag with a present value — including `False` and variant strings — still always wins over the default. `FeatureFlagEvaluations.is_enabled()` already got this in 7.38.0; this closes the gap on the legacy `feature_enabled()` API. Generated-By: PostHog Code Task-Id: c093e5e1-ce99-4af4-a335-7687fe675eee
Contributor
posthog-python Compliance ReportDate: 2026-08-07 16:41:14 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
|
Updates references/public_api_snapshot.txt for the new `default_value` parameter on `Client.feature_enabled()`, fixing the failing "Public API snapshot" CI check. Generated-By: PostHog Code Task-Id: c093e5e1-ce99-4af4-a335-7687fe675eee
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
Brings
feature_enabled()into compliance with the cross-SDKis-feature-enabledcontract in PostHog/sdk-specs: a hardSHALL,@both-tagged requirement that the SDK accept a caller-supplied boolean default and return it whenever the flag has no value (not loaded, failed request, or unknown key) — while any present value, includingFalseand variant strings, still always wins over the default.This was flagged in the sdk-specs compliance matrix (posthog-python.md#n10, "Is Feature Enabled — ❌ Fail"):
feature_enabled()had nodefault_valueparameter at all, unconditionally returningNoneon a miss with no way for a caller to force aTrue/Falsefallback. Its successor,FeatureFlagEvaluations.is_enabled(), already got adefault_valueparameter in 7.38.0 — this PR closes the identical gap on the legacyfeature_enabled()API for parity.Backwards compatibility
Purely additive —
default_valueis a new keyword-only parameter defaulting toNone. Existing callers who don't pass it see byte-for-byte identical behavior (a miss still resolves toNone, matching the spec's allowed variation for three-state boolean APIs). Callers can now opt in to aTrue/Falsefallback on a miss.💚 How did you test it?
posthog/test/test_feature_flags.py: one confirming a caller-supplieddefault_valueis returned on a missing flag or a failed/flagsrequest, another confirming a flag with a real (even falsy) value still wins over the default.test_feature_flags.py+test_evaluate_flags.py+test_client.pysuites (414 tests) — all passing.mypy posthog/client.py— clean.ruff format— clean on touched files.📝 Checklist
If releasing new changes
sampo addto generate a changeset file🤖 Agent context
Autonomy: Fully autonomous — this PR was generated by a scheduled compliance-audit loop that reads the SDK compliance matrices in PostHog/sdk-specs and implements one well-scoped, backward-compatible gap per run. No human directed this specific change; left unassigned for the owning team to triage.
compliance/*.mdin PostHog/sdk-specs.SHALL(not just a nice-to-have), high-impact/widely-used (core flag-evaluation API), narrowly scoped (a single optional parameter), and purely additive — no existing open PR/branch addressed it.is_enabled()/get_flag()); that was left out of scope here to keep this PR focused on the single contract (default_value).Closes the
posthog-python×Is Feature Enabledcell in the sdk-specs compliance matrix.