Skip to content

feat!: remove defaultValue from getFeatureFlag - #917

Merged
turnipdabeets merged 3 commits into
chore/v4-remove-deprecatedfrom
feat/v4-remove-get-feature-flag-default
Nov 2, 2026
Merged

turnipdabeets merged 3 commits into
chore/v4-remove-deprecatedfrom
feat/v4-remove-get-feature-flag-default

Conversation

@turnipdabeets

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

Part of the 4.0 stack on #871. Removes defaultValue from the client getFeatureFlag:

// before
getFeatureFlag(key: String, defaultValue: Any? = null, sendFeatureFlagEvent: Boolean? = null): Any?
// after
getFeatureFlag(key: String, sendFeatureFlagEvent: Boolean? = null): Any?

Migration: getFeatureFlag(key, default) becomes getFeatureFlag(key) ?: default.

Why:

  • The canonical client signature in sdk-specs has no default, and iOS, Flutter and React Native don't have one.
  • A fallback was sent as $feature_flag_response in $feature_flag_called, so it could be reported as the flag's value.

What upgraders should watch for:

Before After
Disabled SDK returned defaultValue Returns null
getFeatureFlag("key", "fallback") Stops compiling
getFeatureFlag("key", true) Still compiles, but true now means sendFeatureFlagEvent
isFeatureEnabled("missing", true) reported true in $feature_flag_called Still returns true, but reports an empty response

The last row is a side effect: isFeatureEnabled goes through getFeatureFlag. Its defaultValue parameter and return value don't change, as the spec requires. It's the same reporting problem, so I didn't add code to preserve it.

Not changed: getFeatureFlagStateless, posthog-server, and PostHogRemoteConfig.getFeatureFlag, which keeps its own defaultValue.

In-repo callers: no production code passed a default. Only isFeatureEnabled and the static PostHog.getFeatureFlag forwarded it. The Flutter and KMP Android code doesn't pass one either.

💚 How did you test it?

  • ./gradlew :posthog:test :posthog-android:testReleaseUnitTest :posthog-server:test :posthog-server-openfeature:test :posthog-android-surveys-compose:testDebugUnitTest apiCheck spotlessCheck with the samples compiled: everything passed except one posthog-android test in that run, PostHogReplayIntegrationTest > bitmap allocation failure feeds the discard counter. It then passed 3 reruns of its class and 3 full reruns of the module, and it doesn't touch flags, so it looks flaky. I didn't find the cause.
  • Replaced the test that expected the default in the event. New tests cover: a missing flag returns null, a default isn't reported from either API, a false flag beats the default, and a disabled SDK returns null / the default.
  • Checked the new tests with 4 temporary mutations (dropping the disabled guard, leaking a fallback, dropping ?: defaultValue, ignoring the flag value). Each one failed the expected tests.

📝 Checklist

  • All commits are signed (see Commit signing)
  • 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 pnpm changeset to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Claude Code (Claude Opus 5.5) made the change, updated callers and the API dump, and ran the tests. A dry-run merge with #881 is clean. No device or manual testing.

🤖 Generated with Claude Code

The canonical client signature has no default and iOS, Flutter and RN have
none. A fallback was also reported as the flag value in $feature_flag_called.
A disabled SDK now returns null; isFeatureEnabled keeps its defaultValue.

@marandaneto marandaneto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good; no qualifying findings. Verdict: correct.

@turnipdabeets
turnipdabeets merged commit 9cf154d into chore/v4-remove-deprecated Nov 2, 2026
11 checks passed
@turnipdabeets
turnipdabeets deleted the feat/v4-remove-get-feature-flag-default branch November 2, 2026 15:08
turnipdabeets added a commit to PostHog/posthog-kmp that referenced this pull request Nov 4, 2026
posthog-android 4.0 removed the defaultValue parameter from
getFeatureFlag (PostHog/posthog-android#917), so the native call now
receives two arguments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants