diff --git a/ee/clickhouse/models/test/test_cohort.py b/ee/clickhouse/models/test/test_cohort.py index c7de1a390f343..fb4831f28723c 100644 --- a/ee/clickhouse/models/test/test_cohort.py +++ b/ee/clickhouse/models/test/test_cohort.py @@ -205,32 +205,6 @@ def test_prop_cohort_with_negation(self): result = sync_execute(final_query, {**params, "team_id": self.team.pk}) self.assertEqual(len(result), 0) - def test_cohort_updated_props(self): - # The way clickhouse works is that updates aren't instant, so two people with the same ID are in the database - # Make sure we get the last one. - person1 = _create_person( - distinct_ids=["some_other_id_2"], - team_id=self.team.pk, - properties={"$some_prop": "updated"}, - timestamp=datetime(2020, 1, 1, 12, 0, 1), - ) - _create_person( - uuid=person1.uuid, - distinct_ids=["some_other_id"], - team_id=self.team.pk, - properties={"$some_prop": "something"}, - timestamp=datetime(2020, 1, 1, 12, 0, 4), - ) - - cohort1 = Cohort.objects.create( - team=self.team, groups=[{"properties": {"$some_prop": "updated"}}], name="cohort1", - ) - - final_query, params = format_filter_query(cohort1) - - result = sync_execute(final_query, {**params, "team_id": self.team.pk}) - self.assertEqual(len(result), 0) - def test_cohort_get_person_ids_by_cohort_id(self): user1 = _create_person(distinct_ids=["user1"], team_id=self.team.pk, properties={"$some_prop": "something"}) user2 = _create_person(distinct_ids=["user2"], team_id=self.team.pk, properties={"$some_prop": "another"}) diff --git a/ee/clickhouse/sql/person.py b/ee/clickhouse/sql/person.py index e54d637ef04ed..4b1623668de2d 100644 --- a/ee/clickhouse/sql/person.py +++ b/ee/clickhouse/sql/person.py @@ -59,8 +59,8 @@ GET_LATEST_PERSON_SQL = """ SELECT * FROM person JOIN ( - SELECT id, max(created_at) as created_at FROM person WHERE team_id = %(team_id)s GROUP BY id -) as person_max ON person.id = person_max.id AND person.created_at = person_max.created_at + SELECT id, max(_timestamp) as _timestamp FROM person WHERE team_id = %(team_id)s GROUP BY id +) as person_max ON person.id = person_max.id AND person._timestamp = person_max._timestamp WHERE team_id = %(team_id)s {query} """