Skip to content

feat: is_enabled() accepts a caller-supplied default_value (sdk-specs is-feature-enabled) - #800

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/is-enabled-default-value
Draft

feat: is_enabled() accepts a caller-supplied default_value (sdk-specs is-feature-enabled)#800
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/is-enabled-default-value

Conversation

@posthog

@posthog posthog Bot commented Jul 30, 2026

Copy link
Copy Markdown

💡 Motivation and Context

The sdk-specs is-feature-enabled contract requires the boolean flag check to accept a caller-supplied boolean default:

  • openspec/specs/is-feature-enabled/spec.mdRequirement: Canonical is-feature-enabled behavior: "The SDK SHALL accept a caller-supplied boolean default (defaultValue; parameter placement per platform idiom) and SHALL return it whenever the flag has no value: flags not loaded yet, a failed flags request, or no flag with that key in the loaded flags. A flag that has a value — including false and variant strings — always wins over the caller-supplied default."
  • Same file, Server-side canonical signature lists defaultValue?: boolean alongside groups, personProperties, onlyEvaluateLocally, etc.
  • Same file, scenarios "Enabled check resolves missing flags to the default" and "Enabled check prefers the flag value over the caller default".

What was out of compliance: FeatureFlagEvaluations.is_enabled(key) — the boolean check on the current, non-deprecated evaluate_flags() path — had no default parameter and hard-coded False for the no-value case. Callers had no way to make a missing flag, an empty evaluation, or a failed /flags request fall back to True.

Notably, the spec change that added this contract (sdk-specs#14 / #15) assumed the server SDKs already exposed it. posthog-python did not.

How this fixes it: is_enabled() gains default_value: bool = False, returned when the key is absent from the snapshot. A flag that has a value still wins, so a disabled flag returns False even with default_value=True.

The deprecated Client.feature_enabled() is intentionally not changed — it is already slated for removal in favor of evaluate_flags(...).is_enabled(key), so the contract is satisfied on the path callers are being steered toward.

💚 How did you test it?

  • New tests in posthog/test/test_evaluate_flags.py covering the three spec scenarios: a missing flag returns the caller default (both False and True), a flag that has a value beats the default (disabled/boolean/variant), and a failed /flags request returns the default.
  • uv run pytest posthog/test/test_evaluate_flags.py — 35 passed.
  • ruff format --check ., ruff check ., mypy … | mypy-baseline filter — all clean.
  • make public_api_snapshot regenerated references/public_api_snapshot.txt (the one changed signature line).

Behavior change / back-compat risk: none for existing callers. default_value defaults to False, which is exactly what is_enabled() returned before for missing flags. The only observable change is additive: passing default_value=True now returns True instead of False for a flag with no value. Public API surface grows by one optional parameter.

📝 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

🤖 Agent context

Autonomy: Fully autonomous

Opened by the SDK Spec Compliance Enforcer loop, which audits posthog-python against the PostHog/sdk-specs contracts and files one focused PR per confirmed divergence.

  • Tools: Claude Code (Bash, Read, Edit, Write, Grep/Glob) plus four parallel read-only Explore subagents, one per group of in-scope capabilities.
  • This run audited ~22 both-scoped specs. Other candidate divergences were found and deliberately not included here to keep the PR focused, or skipped outright: the module-level get_feature_flag_payload tracking default was already filed as fix: don't send $feature_flag_called from module-level get_feature_flag_payload #794 and closed wontfix; the explicit-flush-bypasses-flush_interval gap is already open as fix: flush() delivers pending events without waiting out flush_interval #797; alias/group_identify missing-identifier validation and SizeLimitedDict's wholesale clear at capacity are behavior-changing and left for human triage.
  • default_value was placed on FeatureFlagEvaluations.is_enabled() rather than the deprecated Client.feature_enabled(), since the spec allows platform-idiomatic parameter placement and modifying a deprecated surface adds churn without helping callers.

Created with PostHog Code

The sdk-specs `is-feature-enabled` contract requires the boolean flag check to
accept a caller-supplied boolean default and return it whenever the flag has no
value. `FeatureFlagEvaluations.is_enabled()` hard-coded `False` for that case,
so callers could not force a specific fallback.

Add `default_value: bool = False`. A flag that has a value still wins, so a
disabled flag returns `False` even with `default_value=True`. The default keeps
existing calls behaving exactly as before.

The deprecated `Client.feature_enabled()` is intentionally left unchanged.

Generated-By: PostHog Code
Task-Id: e433896a-0f63-478e-bf90-2c6d7c538d37
@github-actions

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

posthog-python Compliance Report

Date: 2026-07-30 08:00:44 UTC
Duration: 338834ms

✅ 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 518ms
Endpoint And Method.Does Not Use Legacy Endpoints 1009ms
Required Headers.Has Authorization Bearer Header 1009ms
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 1010ms
Required Headers.Has User Agent 1009ms
Body Format.Body Has Created At And Batch 1009ms
Body Format.No Api Key In Body 1008ms
Body Format.No Sent At In Body 1009ms
Event Format.Event Has Required Root Fields 1008ms
Event Format.Event Uuid Is Valid 1009ms
Event Format.Event Timestamp Is Rfc3339 1009ms
Event Format.Distinct Id Is String 1009ms
Event Format.Distinct Id At Root Not Properties 1008ms
Event Format.Custom Properties Preserved 1009ms
Event Format.Set Properties Preserved 1009ms
Event Format.Set Once Properties Preserved 1008ms
Event Format.Groups Properties Preserved 1009ms
Event Format.Sdk Generates Uuid If Not Provided 1009ms
Event Format.Event Has Required Root Fields Batch 1013ms
Event Format.Event Uuid Is Valid Batch 1012ms
Event Format.Event Timestamp Is Rfc3339 Batch 1011ms
Event Format.Distinct Id Is String Batch 1013ms
Event Format.Distinct Id At Root Not Properties Batch 1012ms
Event Format.Custom Properties Preserved Batch 1013ms
Event Format.Set Properties Preserved Batch 1012ms
Event Format.Set Once Properties Preserved Batch 1012ms
Event Format.Groups Properties Preserved Batch 1012ms
Event Format.Sdk Generates Uuid If Not Provided Batch 1013ms
Batch Behavior.Multiple Events In Single Batch 1507ms
Batch Behavior.Batch Envelope Smoke 1014ms
Batch Behavior.Flush With No Events Sends Nothing 1005ms
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 7513ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 7511ms
Deduplication.No Duplicate Events In Batch 1505ms
Header Behavior On Retry.Attempt Header Starts At One 1009ms
Header Behavior On Retry.Attempt Header Increments On Retry 14517ms
Header Behavior On Retry.Request Id Preserved On Retry 7514ms
Header Behavior On Retry.Different Requests Have Different Request Ids 3517ms
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 1507ms
Response Format Validation.Success No Retry After When All Ok 1507ms
Response Format Validation.Success Retry After Present When Retry Events 2511ms
Response Format Validation.Success No Retry After When Drop Only 1507ms
Response Format Validation.Response Echoes Request Id 1009ms
Retry Behavior.Retries On 408 7516ms
Retry Behavior.Retries On 500 7512ms
Retry Behavior.Retries On 503 9514ms
Retry Behavior.Retries On 504 7513ms
Retry Behavior.Retryable Errors Have Retry After 4507ms
Retry Behavior.Respects Retry After On Retryable Error 12518ms
Retry Behavior.Does Not Retry On 400 3503ms
Retry Behavior.Does Not Retry On 401 3507ms
Retry Behavior.Does Not Retry On 402 3509ms
Retry Behavior.Does Not Retry On 413 3506ms
Retry Behavior.Does Not Retry On 415 3508ms
Retry Behavior.Non Retryable Errors Have No Retry After 3508ms
Retry Behavior.Implements Backoff 23522ms
Retry Behavior.Max Retries Respected 23531ms
Partial Batch Handling.Handles 200 Full Success 2998ms
Partial Batch Handling.Handles 200 With All Ok 4510ms
Partial Batch Handling.Does Not Retry Dropped Events 4508ms
Partial Batch Handling.Does Not Retry Limited Events 4509ms
Partial Batch Handling.Prunes Ok Events On Partial Retry 7509ms
Partial Batch Handling.Prunes Dropped Events On Partial Retry 7517ms
Partial Batch Handling.Retries Only Retry Events From Partial 7512ms
Partial Batch Handling.Partial Retry Preserves Uuids 7511ms
Partial Batch Handling.Partial Retry Attempt Header Increments 7509ms
Partial Batch Handling.Partial Retry Request Id Preserved 7516ms
Partial Batch Handling.Respects Retry After On Partial 9511ms
Partial Batch Handling.Unknown Result Treated As Terminal 4507ms
Partial Batch Handling.Mixed Ok Drop Limited No Retry 4508ms
Compression.Sends Gzip Content Encoding 1008ms
Compression.No Content Encoding When Disabled 1008ms
Compression.Compressed Body Is Decompressible 1010ms
Error Handling.Does Not Retry On Unknown 4Xx 3508ms
Event Options.Cookieless Mode Override 1008ms
Event Options.Disable Skew Correction Override 1008ms
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 1009ms
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 1006ms
Request Payload.Flags Request Uses V2 Query Param 1006ms
Request Payload.Flags Request Hits Flags Path Not Decide 1007ms
Request Payload.Flags Request Omits Authorization Header 1006ms
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.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 1007ms
Request Lifecycle.No Flags Request On Init Alone 503ms
Request Lifecycle.No Flags Request On Normal Capture 1508ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 1010ms
Request Lifecycle.Mock Response Value Is Returned To Caller 1003ms
Retry Behavior.Retries Flags On 502 1006ms
Retry Behavior.Retries Flags On 504 1007ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 1509ms

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.

0 participants