-
Notifications
You must be signed in to change notification settings - Fork 31
feat: Add new FeatureFlagResult class and tests #227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a new FeatureFlagResult class and the associated get_feature_flag_result method while updating the existing feature flag payload handling to return deserialized JSON objects. Key changes include:
- Updating the version to 4.0.0 and adding the changelog for the new feature and breaking changes.
- Creating the FeatureFlagResult dataclass with helper constructors and integrating it into the client’s feature flag retrieval flow.
- Adjusting tests to reflect the new feature flag payload format and default behaviors.
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
posthog/version.py | Version bump to 4.0.0 to support the new feature. |
posthog/types.py | Added the FeatureFlagResult dataclass and related methods. |
posthog/test/test_feature_flags.py | Updated test cases to account for JSON payload changes and regex syntax. |
posthog/test/test_feature_flag.py | Adjusted default expected condition_index value as part of the breaking change. |
posthog/client.py | Refactored feature flag methods to use the new FeatureFlagResult and improved local/remote evaluation handling. |
CHANGELOG.md | Documented the new functionality and breaking changes in feature flag payloads. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
This PR introduces a new FeatureFlagResult
class and get_feature_flag_result
method to provide a unified way to access feature flag data, along with a breaking change in payload deserialization.
- Added
FeatureFlagResult
class in/posthog/types.py
with propertiesenabled
,variant
,payload
andget_value()
method - Breaking change:
get_feature_flag_payload
now deserializes JSON string payloads to Python objects instead of returning raw JSON strings - Duplicate test method name
test_from_bool_value_and_payload
in/posthog/test/test_feature_flag_result.py
needs to be fixed - Missing test coverage for invalid JSON payloads and malformed flag definitions
- Version bumped to 4.0.0 in
/posthog/version.py
to reflect breaking API change
7 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great as always, one question about what we decided to return in the FeatureFlagResponse
but nothing blocking.
This provides a "one-shot" method to get both the feature flag result and payload without having to make two decide calls.
Add private `_get_feature_flag_result` method This will also handle the logic for `get_feature_flag_payload`
Now uses the new `_get_feature_flag_result` method.
Fixes #226
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
95196ad
to
f3740d5
Compare
Supporting old Python means we can't have nice things.
347390c
to
27b0965
Compare
27b0965
to
de657b7
Compare
Added new method
get_feature_flag_result
which returns aFeatureFlagResult
object. This object breaks down the result of a feature flag into its enabled state, variant, and payload. The benefit of this method is it allows you to retrieve the result of a feature flag and its payload in a single API call. You can callget_value
on the result to get the value of the feature flag, which is the same value returned byget_feature_flag
(aka the stringvariant
if the flag is a multivariate flag or theboolean
value if the flag is a boolean flag).Example:
🚨 Breaking change⚠️ :
get_feature_flag_payload
now deserializes payloads from JSON strings toAny
. Previously, it returned the payload as a JSON encoded string.Before:
After: