Skip to content

Commit

Permalink
Fix psycopg issues
Browse files Browse the repository at this point in the history
  • Loading branch information
webjunkie committed Nov 17, 2023
1 parent 677d38a commit 9cc26d4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
21 changes: 9 additions & 12 deletions posthog/api/test/__snapshots__/test_feature_flag.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -433,9 +431,9 @@
---
# name: TestResiliency.test_feature_flags_v3_with_experience_continuity_working_slow_db.4
'
SELECT (("posthog_person"."properties" -> 'email') = '"[email protected]"'
SELECT (("posthog_person"."properties" -> 'email') = '"[email protected]"'::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")
Expand All @@ -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,
Expand Down Expand Up @@ -545,12 +542,12 @@
'
SELECT pg_sleep(1);

SELECT (("posthog_person"."properties" -> 'email') = '"[email protected]"'
SELECT (("posthog_person"."properties" -> 'email') = '"[email protected]"'::jsonb
AND "posthog_person"."properties" ? 'email'
AND NOT (("posthog_person"."properties" -> 'email') = 'null')) AS "flag_X_condition_0",
(("posthog_person"."properties" -> 'email') = '"[email protected]"'
AND NOT (("posthog_person"."properties" -> 'email') = 'null'::jsonb)) AS "flag_X_condition_0",
(("posthog_person"."properties" -> 'email') = '"[email protected]"'::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")
Expand Down
30 changes: 15 additions & 15 deletions posthog/api/test/test_feature_flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand All @@ -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)
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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")

Expand Down Expand Up @@ -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"})
Expand All @@ -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)
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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"])
Expand All @@ -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",
Expand Down Expand Up @@ -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"])
Expand Down

0 comments on commit 9cc26d4

Please sign in to comment.