From a0de2b95273fb3df9185615e9bceceed87531edc Mon Sep 17 00:00:00 2001 From: Paul D'Ambra Date: Thu, 19 Dec 2024 14:59:02 +0000 Subject: [PATCH] fix: handle unexpected shaped test account filters --- .../queries/session_recording_list_from_query.py | 5 ++++- .../queries/test/test_session_recording_list_from_query.py | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/posthog/session_recordings/queries/session_recording_list_from_query.py b/posthog/session_recordings/queries/session_recording_list_from_query.py index d53c99682edad..b1819c063f383 100644 --- a/posthog/session_recordings/queries/session_recording_list_from_query.py +++ b/posthog/session_recordings/queries/session_recording_list_from_query.py @@ -182,7 +182,7 @@ def __init__( def _test_account_filters(self) -> list[AnyPropertyFilter]: prop_filters: list[AnyPropertyFilter] = [] for prop in self._team.test_account_filters: - match prop["type"]: + match prop.get("type", None): case "person": prop_filters.append(PersonPropertyFilter(**prop)) case "event": @@ -191,6 +191,9 @@ def _test_account_filters(self) -> list[AnyPropertyFilter]: prop_filters.append(GroupPropertyFilter(**prop)) case "hogql": prop_filters.append(HogQLPropertyFilter(**prop)) + case None: + logger.warn("test account filter had no type", filter=prop) + prop_filters.append(EventPropertyFilter(**prop)) return prop_filters diff --git a/posthog/session_recordings/queries/test/test_session_recording_list_from_query.py b/posthog/session_recordings/queries/test/test_session_recording_list_from_query.py index 35116f4085e55..2acf2a47d5642 100644 --- a/posthog/session_recordings/queries/test/test_session_recording_list_from_query.py +++ b/posthog/session_recordings/queries/test/test_session_recording_list_from_query.py @@ -3316,7 +3316,9 @@ def test_event_filter_with_test_accounts_excluded(self): "key": "is_internal_user", "value": ["false"], "operator": "exact", - "type": "event", + # in production some test account filters don't include type + # we default to event in that case + # "type": "event", }, {"key": "properties.$browser == 'Chrome'", "type": "hogql"}, ]