: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
chore(personhog): fix cohort fetch (#63114)
Zach Brownf0eaccca5078
diff --git a/rust/personhog-replica/.sqlx/query-1094540dc7145671df1ee86bfa3f642d32c375fc398874750593ee943c1aefa9.json b/rust/personhog-replica/.sqlx/query-1094540dc7145671df1ee86bfa3f642d32c375fc398874750593ee943c1aefa9.jsondeleted file mode 100644index 7485955d8f9b..000000000000--- a/rust/personhog-replica/.sqlx/query-1094540dc7145671df1ee86bfa3f642d32c375fc398874750593ee943c1aefa9.json+++ /dev/null@@ -1,16 +0,0 @@-{- "db_name": "PostgreSQL",- "query": "\n INSERT INTO posthog_cohortpeople (person_id, cohort_id, version)\n SELECT pid, $1, $3\n FROM UNNEST($2::bigint[]) AS t(pid)\n WHERE NOT EXISTS (\n SELECT 1 FROM posthog_cohortpeople cp\n WHERE cp.person_id = pid AND cp.cohort_id = $1\n )\n ON CONFLICT DO NOTHING\n ",- "describe": {- "columns": [],- "parameters": {- "Left": [- "Int4",- "Int8Array",- "Int4"- ]- },- "nullable": []- },- "hash": "1094540dc7145671df1ee86bfa3f642d32c375fc398874750593ee943c1aefa9"-}diff --git a/rust/personhog-replica/.sqlx/query-17c8eceeb16929f586c12e2b5b1dc8ad2a553f8ab8263465eda230c62da0908a.json b/rust/personhog-replica/.sqlx/query-17c8eceeb16929f586c12e2b5b1dc8ad2a553f8ab8263465eda230c62da0908a.jsonnew file mode 100644index 000000000000..714ef66b53e3--- /dev/null+++ b/rust/personhog-replica/.sqlx/query-17c8eceeb16929f586c12e2b5b1dc8ad2a553f8ab8263465eda230c62da0908a.json@@ -0,0 +1,23 @@+{+ "db_name": "PostgreSQL",+ "query": "\n SELECT cohort_id::bigint AS \"cohort_id!\"\n FROM posthog_cohortpeople\n WHERE person_id = $1 AND cohort_id = ANY($2::bigint[])\n ",+ "describe": {+ "columns": [+ {+ "ordinal": 0,+ "name": "cohort_id!",+ "type_info": "Int8"+ }+ ],+ "parameters": {+ "Left": [+ "Int8",+ "Int8Array"+ ]+ },+ "nullable": [+ null+ ]+ },+ "hash": "17c8eceeb16929f586c12e2b5b1dc8ad2a553f8ab8263465eda230c62da0908a"+}diff --git a/rust/personhog-replica/.sqlx/query-09b3881157596fef23e996fc93226b55ea37ee17f96b5d0fd64b67edae7fac59.json b/rust/personhog-replica/.sqlx/query-5735d39cbd048343678433aac092b07ca595bc991249d6dd551b834a303fa465.jsonsimilarity index 57%rename from rust/personhog-replica/.sqlx/query-09b3881157596fef23e996fc93226b55ea37ee17f96b5d0fd64b67edae7fac59.jsonrename to rust/personhog-replica/.sqlx/query-5735d39cbd048343678433aac092b07ca595bc991249d6dd551b834a303fa465.jsonindex 3f29cb25c213..03f84980bf37 100644--- a/rust/personhog-replica/.sqlx/query-09b3881157596fef23e996fc93226b55ea37ee17f96b5d0fd64b67edae7fac59.json+++ b/rust/personhog-replica/.sqlx/query-5735d39cbd048343678433aac092b07ca595bc991249d6dd551b834a303fa465.json@@ -1,15 +1,15 @@{"db_name": "PostgreSQL",- "query": "\n DELETE FROM posthog_cohortpeople\n WHERE cohort_id = $1 AND person_id = $2\n ",+ "query": "\n DELETE FROM posthog_cohortpeople\n WHERE cohort_id = $1::bigint AND person_id = $2\n ","describe": {"columns": [],"parameters": {"Left": [- "Int4",+ "Int8","Int8"]},"nullable": []},- "hash": "09b3881157596fef23e996fc93226b55ea37ee17f96b5d0fd64b67edae7fac59"+ "hash": "5735d39cbd048343678433aac092b07ca595bc991249d6dd551b834a303fa465"}diff --git a/rust/personhog-replica/.sqlx/query-c6cac393dd063c3022083b94dc0d8a12b8bd0ea487c1e1f97863c12b30f828f3.json b/rust/personhog-replica/.sqlx/query-9149a91fb9ab2782935bc5e41c94e471792f630e9228e275ea233ac15acc7d18.jsonsimilarity index 58%rename from rust/personhog-replica/.sqlx/query-c6cac393dd063c3022083b94dc0d8a12b8bd0ea487c1e1f97863c12b30f828f3.jsonrename to rust/personhog-replica/.sqlx/query-9149a91fb9ab2782935bc5e41c94e471792f630e9228e275ea233ac15acc7d18.jsonindex 07a048644feb..fc052689e9f6 100644--- a/rust/personhog-replica/.sqlx/query-c6cac393dd063c3022083b94dc0d8a12b8bd0ea487c1e1f97863c12b30f828f3.json+++ b/rust/personhog-replica/.sqlx/query-9149a91fb9ab2782935bc5e41c94e471792f630e9228e275ea233ac15acc7d18.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT person_id\n FROM posthog_cohortpeople\n WHERE cohort_id = $1 AND person_id > $2\n ORDER BY person_id ASC\n LIMIT $3\n ",+ "query": "\n SELECT person_id\n FROM posthog_cohortpeople\n WHERE cohort_id = $1::bigint AND person_id > $2\n ORDER BY person_id ASC\n LIMIT $3\n ","describe": {"columns": [{@@ -11,7 +11,7 @@],"parameters": {"Left": [- "Int4",+ "Int8","Int8","Int8"]@@ -20,5 +20,5 @@false]},- "hash": "c6cac393dd063c3022083b94dc0d8a12b8bd0ea487c1e1f97863c12b30f828f3"+ "hash": "9149a91fb9ab2782935bc5e41c94e471792f630e9228e275ea233ac15acc7d18"}diff --git a/rust/personhog-replica/.sqlx/query-c2b30eb498eeb38752b7c1e2f6ce7103cfcdba943f256c4052d371d7b5b2b871.json b/rust/personhog-replica/.sqlx/query-c2b30eb498eeb38752b7c1e2f6ce7103cfcdba943f256c4052d371d7b5b2b871.jsonnew file mode 100644index 000000000000..4fb048251c4e--- /dev/null+++ b/rust/personhog-replica/.sqlx/query-c2b30eb498eeb38752b7c1e2f6ce7103cfcdba943f256c4052d371d7b5b2b871.json@@ -0,0 +1,16 @@+{+ "db_name": "PostgreSQL",+ "query": "\n INSERT INTO posthog_cohortpeople (person_id, cohort_id, version)\n SELECT pid, $1::bigint, $3\n FROM UNNEST($2::bigint[]) AS t(pid)\n WHERE NOT EXISTS (\n SELECT 1 FROM posthog_cohortpeople cp\n WHERE cp.person_id = pid AND cp.cohort_id = $1::bigint\n )\n ON CONFLICT DO NOTHING\n ",+ "describe": {+ "columns": [],+ "parameters": {+ "Left": [+ "Int8",+ "Int8Array",+ "Int4"+ ]+ },+ "nullable": []+ },+ "hash": "c2b30eb498eeb38752b7c1e2f6ce7103cfcdba943f256c4052d371d7b5b2b871"+}diff --git a/rust/personhog-replica/.sqlx/query-11cd47659f24e416e59e1b290b52282deeb6a12923f28d09af96751a3c56dbdf.json b/rust/personhog-replica/.sqlx/query-e1eb38b96c8e5375eebb8daec7a658ab9848e75da7b5b543488b6b9f9f048263.jsonsimilarity index 56%rename from rust/personhog-replica/.sqlx/query-11cd47659f24e416e59e1b290b52282deeb6a12923f28d09af96751a3c56dbdf.jsonrename to rust/personhog-replica/.sqlx/query-e1eb38b96c8e5375eebb8daec7a658ab9848e75da7b5b543488b6b9f9f048263.jsonindex bb35dea01794..b5adb753984f 100644--- a/rust/personhog-replica/.sqlx/query-11cd47659f24e416e59e1b290b52282deeb6a12923f28d09af96751a3c56dbdf.json+++ b/rust/personhog-replica/.sqlx/query-e1eb38b96c8e5375eebb8daec7a658ab9848e75da7b5b543488b6b9f9f048263.json@@ -1,15 +1,15 @@{"db_name": "PostgreSQL",- "query": "\n DELETE FROM posthog_cohortpeople\n WHERE id IN (\n SELECT id FROM posthog_cohortpeople\n WHERE cohort_id = ANY($1)\n LIMIT $2\n )\n ",+ "query": "\n DELETE FROM posthog_cohortpeople\n WHERE id IN (\n SELECT id FROM posthog_cohortpeople\n WHERE cohort_id = ANY($1::bigint[])\n LIMIT $2\n )\n ","describe": {"columns": [],"parameters": {"Left": [- "Int4Array",+ "Int8Array","Int8"]},"nullable": []},- "hash": "11cd47659f24e416e59e1b290b52282deeb6a12923f28d09af96751a3c56dbdf"+ "hash": "e1eb38b96c8e5375eebb8daec7a658ab9848e75da7b5b543488b6b9f9f048263"}diff --git a/rust/personhog-replica/.sqlx/query-1d214e834f9f4f7fdf71e0f90fd5d29b50e7da987d4269c60485e565da064a38.json b/rust/personhog-replica/.sqlx/query-e5477fd19531f8cfa134a807cd9ed2afa35d57943c40e4e194ab4c7ee753f92c.jsonsimilarity index 74%rename from rust/personhog-replica/.sqlx/query-1d214e834f9f4f7fdf71e0f90fd5d29b50e7da987d4269c60485e565da064a38.jsonrename to rust/personhog-replica/.sqlx/query-e5477fd19531f8cfa134a807cd9ed2afa35d57943c40e4e194ab4c7ee753f92c.jsonindex 54a1f16ddbe0..5387efbfb684 100644--- a/rust/personhog-replica/.sqlx/query-1d214e834f9f4f7fdf71e0f90fd5d29b50e7da987d4269c60485e565da064a38.json+++ b/rust/personhog-replica/.sqlx/query-e5477fd19531f8cfa134a807cd9ed2afa35d57943c40e4e194ab4c7ee753f92c.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT COUNT(*) as \"count!\"\n FROM posthog_cohortpeople\n WHERE cohort_id = ANY($1)\n ",+ "query": "\n SELECT COUNT(*) as \"count!\"\n FROM posthog_cohortpeople\n WHERE cohort_id = ANY($1::bigint[])\n ","describe": {"columns": [{@@ -11,12 +11,12 @@],"parameters": {"Left": [- "Int4Array"+ "Int8Array"]},"nullable": [null]},- "hash": "1d214e834f9f4f7fdf71e0f90fd5d29b50e7da987d4269c60485e565da064a38"+ "hash": "e5477fd19531f8cfa134a807cd9ed2afa35d57943c40e4e194ab4c7ee753f92c"}diff --git a/rust/personhog-replica/.sqlx/query-eb0ad5583168a40eed8ccd5322a2291180afef6ea71964dc53e879bacb04dcd5.json b/rust/personhog-replica/.sqlx/query-eb0ad5583168a40eed8ccd5322a2291180afef6ea71964dc53e879bacb04dcd5.jsondeleted file mode 100644index 6c1cbd98cc31..000000000000--- a/rust/personhog-replica/.sqlx/query-eb0ad5583168a40eed8ccd5322a2291180afef6ea71964dc53e879bacb04dcd5.json+++ /dev/null@@ -1,23 +0,0 @@-{- "db_name": "PostgreSQL",- "query": "\n SELECT cohort_id\n FROM posthog_cohortpeople\n WHERE person_id = $1 AND cohort_id = ANY($2)\n ",- "describe": {- "columns": [- {- "ordinal": 0,- "name": "cohort_id",- "type_info": "Int4"- }- ],- "parameters": {- "Left": [- "Int8",- "Int4Array"- ]- },- "nullable": [- false- ]- },- "hash": "eb0ad5583168a40eed8ccd5322a2291180afef6ea71964dc53e879bacb04dcd5"-}diff --git a/rust/personhog-replica/src/storage/postgres/cohort.rs b/rust/personhog-replica/src/storage/postgres/cohort.rsindex 691d0c6d93df..df7fd0a0933d 100644--- a/rust/personhog-replica/src/storage/postgres/cohort.rs+++ b/rust/personhog-replica/src/storage/postgres/cohort.rs@@ -26,15 +26,15 @@ async fn insert_cohort_members_chunk(let result = sqlx::query!(r#"INSERT INTO posthog_cohortpeople (person_id, cohort_id, version)- SELECT pid, $1, $3+ SELECT pid, $1::bigint, $3FROM UNNEST($2::bigint[]) AS t(pid)WHERE NOT EXISTS (SELECT 1 FROM posthog_cohortpeople cp- WHERE cp.person_id = pid AND cp.cohort_id = $1+ WHERE cp.person_id = pid AND cp.cohort_id = $1::bigint)ON CONFLICT DO NOTHING"#,- cohort_id as i32,+ cohort_id,person_ids,version,)@@ -72,16 +72,17 @@ impl CohortStorage for PostgresStorage {let pool = self.pool_for_consistency(consistency);let mut conn = PostgresStorage::acquire_timed(pool, pool_label).await?;- let cohort_ids_i32: Vec<i32> = cohort_ids.iter().map(|&id| id as i32).collect();-- let member_ids: Vec<i32> = sqlx::query_scalar!(+ // cohort_id::bigint + the bigint[] bind keep this region-agnostic: prod-us widened+ // cohort_id to bigint (out-of-band), while prod-eu and the tracked schema have it as+ // integer. sqlx decodes i64 from the cast either way, so one binary works on both.+ let member_ids: Vec<i64> = sqlx::query_scalar!(r#"- SELECT cohort_id+ SELECT cohort_id::bigint AS "cohort_id!"FROM posthog_cohortpeople- WHERE person_id = $1 AND cohort_id = ANY($2)+ WHERE person_id = $1 AND cohort_id = ANY($2::bigint[])"#,person_id,- &cohort_ids_i32+ cohort_ids).fetch_all(&mut *conn).await?;@@ -99,7 +100,7 @@ impl CohortStorage for PostgresStorage {member_ids.len() as f64,);- let member_set: HashSet<i64> = member_ids.into_iter().map(|id| id as i64).collect();+ let member_set: HashSet<i64> = member_ids.into_iter().collect();Ok(cohort_ids.iter()@@ -133,15 +134,13 @@ impl CohortStorage for PostgresStorage {let pool = self.pool_for_consistency(consistency);let mut conn = PostgresStorage::acquire_timed(pool, pool_label).await?;- let cohort_ids_i32: Vec<i32> = cohort_ids.iter().map(|&id| id as i32).collect();-let count: i64 = sqlx::query_scalar!(r#"SELECT COUNT(*) as "count!"FROM posthog_cohortpeople- WHERE cohort_id = ANY($1)+ WHERE cohort_id = ANY($1::bigint[])"#,- &cohort_ids_i32+ cohort_ids).fetch_one(&mut *conn).await?;@@ -165,9 +164,9 @@ impl CohortStorage for PostgresStorage {let result = sqlx::query!(r#"DELETE FROM posthog_cohortpeople- WHERE cohort_id = $1 AND person_id = $2+ WHERE cohort_id = $1::bigint AND person_id = $2"#,- cohort_id as i32,+ cohort_id,person_id,).execute(&mut *conn)@@ -201,18 +200,16 @@ impl CohortStorage for PostgresStorage {let mut conn =PostgresStorage::acquire_timed(&self.bulk_primary_pool, "bulk_primary").await?;- let cohort_ids_i32: Vec<i32> = cohort_ids.iter().map(|&id| id as i32).collect();-let result = sqlx::query!(r#"DELETE FROM posthog_cohortpeopleWHERE id IN (SELECT id FROM posthog_cohortpeople- WHERE cohort_id = ANY($1)+ WHERE cohort_id = ANY($1::bigint[])LIMIT $2)"#,- &cohort_ids_i32,+ cohort_ids,batch_size as i64,).execute(&mut *conn)@@ -320,11 +317,11 @@ impl CohortStorage for PostgresStorage {r#"SELECT person_idFROM posthog_cohortpeople- WHERE cohort_id = $1 AND person_id > $2+ WHERE cohort_id = $1::bigint AND person_id > $2ORDER BY person_id ASCLIMIT $3"#,- cohort_id as i32,+ cohort_id,cursor,fetch_limit,)