fix: propagate missing params in module-level wrapper functions#479
fix: propagate missing params in module-level wrapper functions#479dustinbyrne wants to merge 2 commits intomasterfrom
Conversation
Propagate distinct_id for group_identify and flag_keys_to_evaluate for get_all_flags/get_all_flags_and_payloads through the module-level wrapper functions in posthog/__init__.py. These parameters were accepted by Client methods but not forwarded by the convenience wrappers, making them inaccessible when using the posthog.group_identify() etc. module-level API.
posthog-python Compliance ReportDate: 2026-04-06 15:53:11 UTC ✅ All Tests Passed!0/0 tests passed |
|
| def test_get_all_flags_propagates_flag_keys_to_evaluate(self): | ||
| posthog.get_all_flags( | ||
| "user_123", | ||
| flag_keys_to_evaluate=["flag-1", "flag-2"], | ||
| ) | ||
| call_kwargs = self.mock_client.get_all_flags.call_args[1] | ||
| self.assertEqual(call_kwargs["flag_keys_to_evaluate"], ["flag-1", "flag-2"]) | ||
|
|
||
| def test_get_all_flags_flag_keys_defaults_to_none(self): | ||
| posthog.get_all_flags("user_123") | ||
| call_kwargs = self.mock_client.get_all_flags.call_args[1] | ||
| self.assertIsNone(call_kwargs["flag_keys_to_evaluate"]) | ||
|
|
||
| def test_get_all_flags_and_payloads_propagates_flag_keys_to_evaluate(self): | ||
| posthog.get_all_flags_and_payloads( | ||
| "user_123", | ||
| flag_keys_to_evaluate=["flag-1", "flag-2"], | ||
| ) | ||
| call_kwargs = self.mock_client.get_all_flags_and_payloads.call_args[1] | ||
| self.assertEqual(call_kwargs["flag_keys_to_evaluate"], ["flag-1", "flag-2"]) | ||
|
|
||
| def test_get_all_flags_and_payloads_flag_keys_defaults_to_none(self): | ||
| posthog.get_all_flags_and_payloads("user_123") | ||
| call_kwargs = self.mock_client.get_all_flags_and_payloads.call_args[1] | ||
| self.assertIsNone(call_kwargs["flag_keys_to_evaluate"]) |
There was a problem hiding this comment.
Prefer parameterised tests for duplicate test cases
The four tests covering get_all_flags and get_all_flags_and_payloads are structurally identical — the only difference is which function is called. The project's convention (used in test_utils.py, test_client.py, etc.) is to use @parameterized.expand to avoid this duplication. For example:
from parameterized import parameterized
@parameterized.expand([
("get_all_flags", posthog.get_all_flags, "get_all_flags"),
("get_all_flags_and_payloads", posthog.get_all_flags_and_payloads, "get_all_flags_and_payloads"),
])
def test_flag_keys_to_evaluate_propagated(self, _name, fn, client_method_name):
fn("user_123", flag_keys_to_evaluate=["flag-1", "flag-2"])
call_kwargs = getattr(self.mock_client, client_method_name).call_args[1]
self.assertEqual(call_kwargs["flag_keys_to_evaluate"], ["flag-1", "flag-2"])
@parameterized.expand([
("get_all_flags", posthog.get_all_flags, "get_all_flags"),
("get_all_flags_and_payloads", posthog.get_all_flags_and_payloads, "get_all_flags_and_payloads"),
])
def test_flag_keys_defaults_to_none(self, _name, fn, client_method_name):
fn("user_123")
call_kwargs = getattr(self.mock_client, client_method_name).call_args[1]
self.assertIsNone(call_kwargs["flag_keys_to_evaluate"])Prompt To Fix With AI
This is a comment left during a code review.
Path: posthog/test/test_module.py
Line: 71-95
Comment:
**Prefer parameterised tests for duplicate test cases**
The four tests covering `get_all_flags` and `get_all_flags_and_payloads` are structurally identical — the only difference is which function is called. The project's convention (used in `test_utils.py`, `test_client.py`, etc.) is to use `@parameterized.expand` to avoid this duplication. For example:
```python
from parameterized import parameterized
@parameterized.expand([
("get_all_flags", posthog.get_all_flags, "get_all_flags"),
("get_all_flags_and_payloads", posthog.get_all_flags_and_payloads, "get_all_flags_and_payloads"),
])
def test_flag_keys_to_evaluate_propagated(self, _name, fn, client_method_name):
fn("user_123", flag_keys_to_evaluate=["flag-1", "flag-2"])
call_kwargs = getattr(self.mock_client, client_method_name).call_args[1]
self.assertEqual(call_kwargs["flag_keys_to_evaluate"], ["flag-1", "flag-2"])
@parameterized.expand([
("get_all_flags", posthog.get_all_flags, "get_all_flags"),
("get_all_flags_and_payloads", posthog.get_all_flags_and_payloads, "get_all_flags_and_payloads"),
])
def test_flag_keys_defaults_to_none(self, _name, fn, client_method_name):
fn("user_123")
call_kwargs = getattr(self.mock_client, client_method_name).call_args[1]
self.assertIsNone(call_kwargs["flag_keys_to_evaluate"])
```
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Problem
The module-level convenience functions in
posthog/__init__.py(e.g.posthog.group_identify(),posthog.get_all_flags()) were missing parameters that the underlyingClientmethods accept:group_identify: missingdistinct_id— callers couldn't specify a stable distinct ID, causing a random UUID to be generated on every call. This creates a garbage person record in the backend on each invocation.get_all_flags: missingflag_keys_to_evaluate— callers couldn't limit evaluation to a subset of flags.get_all_flags_and_payloads: same missingflag_keys_to_evaluate.Changes
distinct_idparameter togroup_identify()wrapper and forwarded it to the client.flag_keys_to_evaluateparameter toget_all_flags()andget_all_flags_and_payloads()wrappers and forwarded them to the client.test_module.pyverifying all three params are propagated correctly (value forwarding + default-to-None).