Skip to content

Commit 67f9781

Browse files
committed
fix(flags): avoid implicit defaultdict insert in capture cache
1 parent 29424bb commit 67f9781

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

‎posthog/client.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,10 +1928,12 @@ def _capture_feature_flag_called(
19281928
f"{key}_{'::null::' if response is None else str(response)}"
19291929
)
19301930

1931-
if (
1932-
feature_flag_reported_key
1933-
not in self.distinct_ids_feature_flags_reported[distinct_id]
1934-
):
1931+
reported_flags = self.distinct_ids_feature_flags_reported.get(distinct_id)
1932+
if reported_flags is None:
1933+
reported_flags = set()
1934+
self.distinct_ids_feature_flags_reported[distinct_id] = reported_flags
1935+
1936+
if feature_flag_reported_key not in reported_flags:
19351937
properties: dict[str, Any] = {
19361938
"$feature_flag": key,
19371939
"$feature_flag_response": response,
@@ -1967,9 +1969,7 @@ def _capture_feature_flag_called(
19671969
groups=groups,
19681970
disable_geoip=disable_geoip,
19691971
)
1970-
self.distinct_ids_feature_flags_reported[distinct_id].add(
1971-
feature_flag_reported_key
1972-
)
1972+
reported_flags.add(feature_flag_reported_key)
19731973

19741974
def get_remote_config_payload(self, key: str):
19751975
if self.disabled:

0 commit comments

Comments
 (0)