: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(feature-flags): resolve person via index-friendly lookup in flag test endpoint (#61864)
Gustavo H. Strassburgerd506cf0a16b9
diff --git a/posthog/models/person/point_in_time_properties.py b/posthog/models/person/point_in_time_properties.pyindex a65de537a7b8..81102af4078b 100644--- a/posthog/models/person/point_in_time_properties.py+++ b/posthog/models/person/point_in_time_properties.py@@ -58,10 +58,14 @@ def get_person_and_distinct_ids_for_identifier(if person_id is not None and not person_id:raise ValueError("person_id must be a non-empty value")- from posthog.models.person.util import get_person_by_distinct_id, get_person_by_uuid+ from posthog.models.person.util import get_person_by_uuid, get_persons_by_distinct_idsif distinct_id is not None:- person = get_person_by_distinct_id(team_id, distinct_id)+ # Plural lookup: index-friendly __in query that also prefetches distinct_ids_cache,+ # which the person.distinct_ids return below relies on. The singular+ # get_person_by_distinct_id times out on large teams.+ persons = get_persons_by_distinct_ids(team_id, [distinct_id])+ person = persons[0] if persons else Noneelse:assert person_id is not Noneperson = get_person_by_uuid(team_id, person_id)diff --git a/posthog/models/person/test/test_point_in_time_properties.py b/posthog/models/person/test/test_point_in_time_properties.pyindex 82909fcfcbeb..64e0cab8ee3a 100644--- a/posthog/models/person/test/test_point_in_time_properties.py+++ b/posthog/models/person/test/test_point_in_time_properties.py@@ -241,8 +241,8 @@ class TestGetPersonAndDistinctIdsForIdentifierPersonhog(SimpleTestCase):assert str(person.uuid) == "00000000-0000-0000-0000-000000000042"assert person.properties == {"email": "[email protected]"}assert set(dids) == {"d1", "d2"}- fake.assert_called("get_person_by_distinct_id")- fake.assert_called("get_distinct_ids_for_person")+ fake.assert_called("get_persons_by_distinct_ids_in_team")+ fake.assert_called("get_distinct_ids_for_persons")def test_lookup_by_person_id(self):with fake_personhog_client() as fake:@@ -270,7 +270,7 @@ class TestGetPersonAndDistinctIdsForIdentifierPersonhog(SimpleTestCase):assert person is Noneassert dids == []- fake.assert_called("get_person_by_distinct_id")+ fake.assert_called("get_persons_by_distinct_ids_in_team")def test_distinct_ids_from_personhog_used_directly(self):with fake_personhog_client() as fake:@@ -316,7 +316,7 @@ class TestGetPersonAndDistinctIdsForIdentifierIntegration(PersonhogTestMixin, Baassert str(result_person.uuid) == str(person.uuid)assert result_person.properties == {"email": "[email protected]"}assert set(result_dids) == {"d1", "d2"}- self._assert_personhog_called("get_person_by_distinct_id")+ self._assert_personhog_called("get_persons_by_distinct_ids_in_team")def test_lookup_by_person_id(self):person = self._seed_person(