Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(customer-analytics): restore calendar person matching (#79936)

Arthur Moreira de Deus0657e6c93555
diff --git a/products/customer_analytics/backend/logic/calendar_sync.py b/products/customer_analytics/backend/logic/calendar_sync.py
index d3d6b32a6c43..7a2c704ba1d4 100644
--- a/products/customer_analytics/backend/logic/calendar_sync.py
+++ b/products/customer_analytics/backend/logic/calendar_sync.py
@@ -38,7 +38,7 @@ ORDER BY is_identified DESC, created_at ASC, id ASC
GROUP_KEY_BY_DISTINCT_ID_QUERY = """
SELECT distinct_id, argMaxIf({group_col}, timestamp, {group_col} != '') AS group_key
FROM events
-WHERE distinct_id IN {distinct_ids} AND timestamp > now() - INTERVAL 90 DAY
+WHERE distinct_id IN {{distinct_ids}} AND timestamp > now() - INTERVAL 90 DAY
GROUP BY distinct_id
"""
diff --git a/products/customer_analytics/backend/test/test_calendar_sync.py b/products/customer_analytics/backend/test/test_calendar_sync.py
index ce7e10eb23c3..8b92b837abf0 100644
--- a/products/customer_analytics/backend/test/test_calendar_sync.py
+++ b/products/customer_analytics/backend/test/test_calendar_sync.py
@@ -150,6 +150,26 @@ class TestCalendarSync(BaseTest):
self._sync([_pages_response([event])])
assert Meeting.objects.for_team(self.team.id).get().account_id == account.id
+ def test_matches_account_via_person_group(self) -> None:
+ self.team.customer_analytics_config.account_group_type_index = 0
+ self.team.customer_analytics_config.save()
+ account = Account.objects.for_team(self.team.id).create(team=self.team, name="Acme", external_id="acme")
+ person_uuid = "0198b6f3-0000-0000-0000-000000000001"
+ person = MagicMock(uuid=person_uuid, distinct_ids=["person-distinct-id"])
+ group_query_response = MagicMock(results=[["person-distinct-id", "acme"]])
+
+ with (
+ patch.object(calendar_sync, "get_persons_by_uuids", return_value=[person]),
+ patch("posthog.hogql.query.execute_hogql_query", return_value=group_query_response),
+ ):
+ counts = self._sync(
+ [_pages_response([_event()])],
+ person_uuids={"[email protected]": person_uuid},
+ )
+
+ assert Meeting.objects.for_team(self.team.id).get().account_id == account.id
+ assert counts.matched == 1
+
def test_removed_attendee_is_deleted_on_resync(self):
self._sync([_pages_response([_event()])])
assert MeetingParticipant.objects.for_team(self.team.id).count() == 2