Skip to content

Commit

Permalink
fix(flags): Ensure feature properties exist on feature flag called ev… (
Browse files Browse the repository at this point in the history
#101)

* fix(flags): Ensure feature properties exist on feature flag called events

* fix

* make flake8 happy, will this bork?
  • Loading branch information
neilkakkar authored Aug 17, 2023
1 parent f75d924 commit 139258c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.0.2 - 2023-08-17

1. Returns the current flag property with $feature_flag_called events, to make it easier to use in experiments

## 3.0.1 - 2023-04-21

1. Restore how feature flags work when the client library is disabled: All requests return `None` and no events are sent when the client is disabled.
Expand Down
1 change: 1 addition & 0 deletions posthog/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ def get_feature_flag(
"$feature_flag": key,
"$feature_flag_response": response,
"locally_evaluated": flag_was_locally_evaluated,
f"$feature/{key}": response,
},
groups=groups,
disable_geoip=disable_geoip,
Expand Down
8 changes: 4 additions & 4 deletions posthog/feature_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,16 @@ def match_property(property, property_values) -> bool:
return is_valid_regex(str(value)) and re.compile(str(value)).search(str(override_value)) is None

if operator == "gt":
return type(override_value) == type(value) and override_value > value
return type(override_value) is type(value) and override_value > value

if operator == "gte":
return type(override_value) == type(value) and override_value >= value
return type(override_value) is type(value) and override_value >= value

if operator == "lt":
return type(override_value) == type(value) and override_value < value
return type(override_value) is type(value) and override_value < value

if operator == "lte":
return type(override_value) == type(value) and override_value <= value
return type(override_value) is type(value) and override_value <= value

if operator in ["is_date_before", "is_date_after"]:
try:
Expand Down
35 changes: 30 additions & 5 deletions posthog/test/test_feature_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -1888,7 +1888,12 @@ def test_capture_is_called(self, patch_decide, patch_capture):
patch_capture.assert_called_with(
"some-distinct-id",
"$feature_flag_called",
{"$feature_flag": "complex-flag", "$feature_flag_response": True, "locally_evaluated": True},
{
"$feature_flag": "complex-flag",
"$feature_flag_response": True,
"locally_evaluated": True,
"$feature/complex-flag": True,
},
groups={},
disable_geoip=None,
)
Expand All @@ -1913,7 +1918,12 @@ def test_capture_is_called(self, patch_decide, patch_capture):
patch_capture.assert_called_with(
"some-distinct-id2",
"$feature_flag_called",
{"$feature_flag": "complex-flag", "$feature_flag_response": True, "locally_evaluated": True},
{
"$feature_flag": "complex-flag",
"$feature_flag_response": True,
"locally_evaluated": True,
"$feature/complex-flag": True,
},
groups={},
disable_geoip=None,
)
Expand Down Expand Up @@ -1946,7 +1956,12 @@ def test_capture_is_called(self, patch_decide, patch_capture):
patch_capture.assert_called_with(
"some-distinct-id2",
"$feature_flag_called",
{"$feature_flag": "decide-flag", "$feature_flag_response": "decide-value", "locally_evaluated": False},
{
"$feature_flag": "decide-flag",
"$feature_flag_response": "decide-value",
"locally_evaluated": False,
"$feature/decide-flag": "decide-value",
},
groups={"organization": "org1"},
disable_geoip=None,
)
Expand Down Expand Up @@ -1984,7 +1999,12 @@ def test_disable_geoip_get_flag_capture_call(self, patch_decide, patch_capture):
patch_capture.assert_called_with(
"some-distinct-id",
"$feature_flag_called",
{"$feature_flag": "complex-flag", "$feature_flag_response": True, "locally_evaluated": True},
{
"$feature_flag": "complex-flag",
"$feature_flag_response": True,
"locally_evaluated": True,
"$feature/complex-flag": True,
},
groups={},
disable_geoip=False,
)
Expand Down Expand Up @@ -2018,7 +2038,12 @@ def test_capture_multiple_users_doesnt_out_of_memory(self, patch_decide, patch_c
patch_capture.assert_called_with(
distinct_id,
"$feature_flag_called",
{"$feature_flag": "complex-flag", "$feature_flag_response": True, "locally_evaluated": True},
{
"$feature_flag": "complex-flag",
"$feature_flag_response": True,
"locally_evaluated": True,
"$feature/complex-flag": True,
},
groups={},
disable_geoip=None,
)
Expand Down
2 changes: 1 addition & 1 deletion posthog/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = "3.0.1"
VERSION = "3.0.2"

if __name__ == "__main__":
print(VERSION, end="") # noqa: T201

0 comments on commit 139258c

Please sign in to comment.