Skip to content

Conversation

@andehen
Copy link
Contributor

@andehen andehen commented Jan 12, 2026

Add device_id parameter to all feature flag methods, similar to how
distinct_id is handled. The device_id is included in the flags request
payload sent to the server.

  • Add device_id parameter to get_flags_decision and related methods
  • Add context support via set_context_device_id() for automatic fallback
  • Add tests for explicit device_id and context-based device_id

This is required for supporting device_id as bucketing identifier.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 12, 2026

Greptile Summary

Overview

This PR adds support for device_id as a bucketing identifier in feature flag evaluations. The implementation adds device_id parameter to feature flag methods and context support via set_context_device_id().

What Works Well

Client methods: All Client class feature flag methods properly accept device_id parameter and pass it through to the flags API
Context support: set_context_device_id() and get_context_device_id() are correctly implemented in the context system
Fallback logic: Device ID properly falls back to context when not explicitly provided, matching the pattern used for distinct_id
Request payload: The device_id is correctly included in the flags request payload sent to the server
Test coverage: Tests verify explicit device_id passing and context-based device_id for Client methods

Critical Issue Found

Missing device_id in module-level functions: All module-level feature flag functions in posthog/__init__.py are missing the device_id parameter:

  • posthog.feature_enabled()
  • posthog.get_feature_flag()
  • posthog.get_all_flags()
  • posthog.get_feature_flag_result()
  • posthog.get_feature_flag_payload()
  • posthog.get_all_flags_and_payloads()

While users can work around this by using set_context_device_id(), this creates an inconsistency: these functions require distinct_id as an explicit parameter (even though it can also come from context). For completeness and consistency with the stated goal of "adding device_id parameter to all feature flag methods", these functions should also accept an optional device_id parameter.

Recommendation

Add the optional device_id parameter to all module-level feature flag functions in posthog/__init__.py and pass it through to the underlying Client methods. This ensures API consistency and fully delivers on the PR's objective.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 12, 2026

Additional Comments (1)

posthog/__init__.py
The feature_enabled() function is missing the device_id parameter. According to the PR description, "device_id parameter should be added to all feature flag methods."

While users can use set_context_device_id() to set device_id via context, this creates an inconsistency: the function requires distinct_id as an explicit parameter even though distinct_id can also come from context in Client methods. For consistency with the Client implementation and to fully support the stated goal, this function should accept an optional device_id parameter.

The same issue applies to:

  • get_feature_flag() (line 551)
  • get_all_flags() (line 601)
  • get_feature_flag_result() (line 643)
  • get_feature_flag_payload() (line 686)
  • get_all_flags_and_payloads() (line 731)

All these module-level functions should be updated to accept an optional device_id parameter and pass it through to the underlying Client methods via _proxy().

Prompt To Fix With AI
This is a comment left during a code review.
Path: posthog/__init__.py
Line: 500:548

Comment:
The `feature_enabled()` function is missing the `device_id` parameter. According to the PR description, "device_id parameter should be added to all feature flag methods."

While users can use `set_context_device_id()` to set device_id via context, this creates an inconsistency: the function requires `distinct_id` as an explicit parameter even though `distinct_id` can also come from context in Client methods. For consistency with the Client implementation and to fully support the stated goal, this function should accept an optional `device_id` parameter.

The same issue applies to:
- `get_feature_flag()` (line 551)
- `get_all_flags()` (line 601)
- `get_feature_flag_result()` (line 643)
- `get_feature_flag_payload()` (line 686)
- `get_all_flags_and_payloads()` (line 731)

All these module-level functions should be updated to accept an optional `device_id` parameter and pass it through to the underlying Client methods via `_proxy()`.

How can I resolve this? If you propose a fix, please make it concise.

Add device_id parameter to all feature flag methods, similar to how
distinct_id is handled. The device_id is included in the flags request
payload sent to the server.

- Add device_id parameter to Client methods and module-level functions
- Add context support via set_context_device_id() for automatic fallback
- Add tests for explicit device_id and context-based device_id
- Bump version to 7.6.0

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@andehen andehen force-pushed the send-device-id-on-flags-requests branch from 1bebd90 to 95b8110 Compare January 12, 2026 12:23
@andehen andehen requested review from a team January 12, 2026 12:47
@posthog-project-board-bot posthog-project-board-bot bot moved this to In Review in Feature Flags Jan 12, 2026
Copy link
Collaborator

@haacked haacked left a comment

Choose a reason for hiding this comment

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

This looks good!

@github-project-automation github-project-automation bot moved this from In Review to Approved in Feature Flags Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved

Development

Successfully merging this pull request may close these issues.

3 participants