From 9cc26d44d0aa9ac8854a34ee1bee3dcb0b9ed4bc Mon Sep 17 00:00:00 2001 From: Julian Bez Date: Fri, 17 Nov 2023 16:16:11 +0100 Subject: [PATCH] Fix psycopg issues --- .../test/__snapshots__/test_feature_flag.ambr | 21 ++++++------- posthog/api/test/test_feature_flag.py | 30 +++++++++---------- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/posthog/api/test/__snapshots__/test_feature_flag.ambr b/posthog/api/test/__snapshots__/test_feature_flag.ambr index 6fc6c63c17f20..26fd3b9ec6741 100644 --- a/posthog/api/test/__snapshots__/test_feature_flag.ambr +++ b/posthog/api/test/__snapshots__/test_feature_flag.ambr @@ -341,8 +341,7 @@ person_id FROM posthog_persondistinctid WHERE team_id = 2 - AND distinct_id IN ('example_id', - 'random') ), + AND distinct_id = ANY('{example_id,random}') ), existing_overrides AS (SELECT team_id, person_id, @@ -371,8 +370,7 @@ person_id FROM posthog_persondistinctid WHERE team_id = 2 - AND distinct_id IN ('example_id', - 'random') ), + AND distinct_id = ANY('{example_id,random}') ), existing_overrides AS (SELECT team_id, person_id, @@ -433,9 +431,9 @@ --- # name: TestResiliency.test_feature_flags_v3_with_experience_continuity_working_slow_db.4 ' - SELECT (("posthog_person"."properties" -> 'email') = '"tim@posthog.com"' + SELECT (("posthog_person"."properties" -> 'email') = '"tim@posthog.com"'::jsonb AND "posthog_person"."properties" ? 'email' - AND NOT (("posthog_person"."properties" -> 'email') = 'null')) AS "flag_X_condition_0", + AND NOT (("posthog_person"."properties" -> 'email') = 'null'::jsonb)) AS "flag_X_condition_0", (true) AS "flag_X_condition_0" FROM "posthog_person" INNER JOIN "posthog_persondistinctid" ON ("posthog_person"."id" = "posthog_persondistinctid"."person_id") @@ -453,8 +451,7 @@ person_id FROM posthog_persondistinctid WHERE team_id = 2 - AND distinct_id IN ('example_id', - 'random') ), + AND distinct_id = ANY('{example_id,random}') ), existing_overrides AS (SELECT team_id, person_id, @@ -545,12 +542,12 @@ ' SELECT pg_sleep(1); - SELECT (("posthog_person"."properties" -> 'email') = '"tim@posthog.com"' + SELECT (("posthog_person"."properties" -> 'email') = '"tim@posthog.com"'::jsonb AND "posthog_person"."properties" ? 'email' - AND NOT (("posthog_person"."properties" -> 'email') = 'null')) AS "flag_X_condition_0", - (("posthog_person"."properties" -> 'email') = '"tim@posthog.com"' + AND NOT (("posthog_person"."properties" -> 'email') = 'null'::jsonb)) AS "flag_X_condition_0", + (("posthog_person"."properties" -> 'email') = '"tim@posthog.com"'::jsonb AND "posthog_person"."properties" ? 'email' - AND NOT (("posthog_person"."properties" -> 'email') = 'null')) AS "flag_X_condition_0", + AND NOT (("posthog_person"."properties" -> 'email') = 'null'::jsonb)) AS "flag_X_condition_0", (true) AS "flag_X_condition_0" FROM "posthog_person" INNER JOIN "posthog_persondistinctid" ON ("posthog_person"."id" = "posthog_persondistinctid"."person_id") diff --git a/posthog/api/test/test_feature_flag.py b/posthog/api/test/test_feature_flag.py index 0c6581a389561..22e42b06a445a 100644 --- a/posthog/api/test/test_feature_flag.py +++ b/posthog/api/test/test_feature_flag.py @@ -4128,7 +4128,7 @@ def test_feature_flags_v3_with_group_properties(self, *args): self.assertTrue(serialized_data.is_valid()) serialized_data.save() - with self.assertNumQueries(4): + with self.assertNumQueries(8): # one query to get group type mappings, another to get group properties # 2 to set statement timeout all_flags, _, _, errors = get_all_feature_flags(team_id, "example_id", groups={"organization": "org:1"}) @@ -4138,7 +4138,7 @@ def test_feature_flags_v3_with_group_properties(self, *args): # now db is down with snapshot_postgres_queries_context(self), connection.execute_wrapper(QueryTimeoutWrapper()): - with self.assertNumQueries(1): + with self.assertNumQueries(3): all_flags, _, _, errors = get_all_feature_flags(team_id, "example_id", groups={"organization": "org:1"}) self.assertTrue("group-flag" not in all_flags) @@ -4147,7 +4147,7 @@ def test_feature_flags_v3_with_group_properties(self, *args): self.assertTrue(errors) # # now db is down, but decide was sent correct group property overrides - with self.assertNumQueries(1): + with self.assertNumQueries(3): all_flags, _, _, errors = get_all_feature_flags( team_id, "random", @@ -4160,7 +4160,7 @@ def test_feature_flags_v3_with_group_properties(self, *args): self.assertTrue(errors) # # now db is down, but decide was sent different group property overrides - with self.assertNumQueries(1): + with self.assertNumQueries(3): all_flags, _, _, errors = get_all_feature_flags( team_id, "exam", @@ -4226,7 +4226,7 @@ def test_feature_flags_v3_with_person_properties(self, mock_counter, *args): self.assertTrue(serialized_data.is_valid()) serialized_data.save() - with self.assertNumQueries(2): + with self.assertNumQueries(4): # 1 query to get person properties # 1 to set statement timeout all_flags, _, _, errors = get_all_feature_flags(team_id, "example_id") @@ -4324,7 +4324,7 @@ def test_feature_flags_v3_with_a_working_slow_db(self, mock_postgres_check): self.assertTrue(serialized_data.is_valid()) serialized_data.save() - with self.assertNumQueries(2): + with self.assertNumQueries(4): # 1 query to set statement timeout # 1 query to get person properties all_flags, _, _, errors = get_all_feature_flags(team_id, "example_id") @@ -4434,7 +4434,7 @@ def test_feature_flags_v3_with_slow_db_doesnt_try_to_compute_conditions_again(se created_by=self.user, ) - with self.assertNumQueries(2): + with self.assertNumQueries(4): # 1 query to get person properties # 1 query to set statement timeout all_flags, _, _, errors = get_all_feature_flags(team_id, "example_id") @@ -4447,7 +4447,7 @@ def test_feature_flags_v3_with_slow_db_doesnt_try_to_compute_conditions_again(se with snapshot_postgres_queries_context(self), connection.execute_wrapper(slow_query), patch( "posthog.models.feature_flag.flag_matching.FLAG_MATCHING_QUERY_TIMEOUT_MS", 500, - ), self.assertNumQueries(2): + ), self.assertNumQueries(4): # no extra queries to get person properties for the second flag after first one failed all_flags, _, _, errors = get_all_feature_flags(team_id, "example_id") @@ -4526,7 +4526,7 @@ def test_feature_flags_v3_with_group_properties_and_slow_db(self, mock_counter, self.assertTrue(serialized_data.is_valid()) serialized_data.save() - with self.assertNumQueries(4): + with self.assertNumQueries(8): # one query to get group type mappings, another to get group properties # 2 queries to set statement timeout all_flags, _, _, errors = get_all_feature_flags(team_id, "example_id", groups={"organization": "org:1"}) @@ -4539,7 +4539,7 @@ def test_feature_flags_v3_with_group_properties_and_slow_db(self, mock_counter, "posthog.models.feature_flag.flag_matching.FLAG_MATCHING_QUERY_TIMEOUT_MS", 500, ): - with self.assertNumQueries(2): + with self.assertNumQueries(4): all_flags, _, _, errors = get_all_feature_flags(team_id, "example_id", groups={"organization": "org:1"}) self.assertTrue("group-flag" not in all_flags) @@ -4548,7 +4548,7 @@ def test_feature_flags_v3_with_group_properties_and_slow_db(self, mock_counter, self.assertTrue(errors) # # now db is slow, but decide was sent correct group property overrides - with self.assertNumQueries(2): + with self.assertNumQueries(4): all_flags, _, _, errors = get_all_feature_flags( team_id, "random", @@ -4570,7 +4570,7 @@ def test_feature_flags_v3_with_group_properties_and_slow_db(self, mock_counter, ) # # now db is down, but decide was sent different group property overrides - with self.assertNumQueries(2): + with self.assertNumQueries(4): all_flags, _, _, errors = get_all_feature_flags( team_id, "exam", @@ -4637,7 +4637,7 @@ def test_feature_flags_v3_with_experience_continuity_working_slow_db(self, mock_ self.assertTrue(serialized_data.is_valid()) serialized_data.save() - with snapshot_postgres_queries_context(self), self.assertNumQueries(9): + with snapshot_postgres_queries_context(self), self.assertNumQueries(17): all_flags, _, _, errors = get_all_feature_flags(team_id, "example_id", hash_key_override="random") self.assertTrue(all_flags["property-flag"]) @@ -4657,7 +4657,7 @@ def test_feature_flags_v3_with_experience_continuity_working_slow_db(self, mock_ # # now db is slow, but decide was sent email parameter with correct email # still need to get hash key override from db, so should time out - with self.assertNumQueries(2): + with self.assertNumQueries(4): all_flags, _, _, errors = get_all_feature_flags( team_id, "random", @@ -4729,7 +4729,7 @@ def test_feature_flags_v3_with_experience_continuity_and_incident_mode(self, moc self.assertTrue(serialized_data.is_valid()) serialized_data.save() - with self.assertNumQueries(5), self.settings(DECIDE_SKIP_HASH_KEY_OVERRIDE_WRITES=True): + with self.assertNumQueries(9), self.settings(DECIDE_SKIP_HASH_KEY_OVERRIDE_WRITES=True): all_flags, _, _, errors = get_all_feature_flags(team_id, "example_id", hash_key_override="random") self.assertTrue(all_flags["property-flag"])