Skip to content

: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.

chore(tests): stop signals emit fixture leaking committed orgs across product suites (#70255)

Paul D'Ambra2710f4fee79b
diff --git a/products/signals/backend/test/test_scout_harness_tools.py b/products/signals/backend/test/test_scout_harness_tools.py
index a93724db4bfb..28fcdddec405 100644
--- a/products/signals/backend/test/test_scout_harness_tools.py
+++ b/products/signals/backend/test/test_scout_harness_tools.py
@@ -700,7 +700,12 @@ async def aorganization_emit():
org = await database_sync_to_async(Organization.objects.create)(
name="signals-scout-emit", is_ai_data_processing_approved=True
)
- return org
+ yield org
+ # database_sync_to_async writes commit on an executor-thread connection, outside the
+ # test's transaction, so this delete is the only cleanup these rows get. Without it every
+ # emit test leaks a committed org into the shared --reuse-db database and poisons later
+ # product suites in the same CI job (cascade also removes the team/config/run fixtures).
+ await database_sync_to_async(org.delete)()
@pytest_asyncio.fixture
diff --git a/products/web_analytics/backend/test/test_digest_notification_activities.py b/products/web_analytics/backend/test/test_digest_notification_activities.py
index 6a32abe83344..1cbc97c814f2 100644
--- a/products/web_analytics/backend/test/test_digest_notification_activities.py
+++ b/products/web_analytics/backend/test/test_digest_notification_activities.py
@@ -384,9 +384,12 @@ class TestGetOrgBatchPage(_DigestNotificationTestBase):
assert page.cursor is None
def test_keyset_pagination_pages_through_orgs(self):
- orgs = [self.organization]
- orgs.extend(Organization.objects.create(name=f"Org {i}") for i in range(4))
- expected_ids = sorted(str(org.id) for org in orgs)
+ for i in range(4):
+ Organization.objects.create(name=f"Org {i}")
+ # Expected ids come from the database rather than just the orgs created above:
+ # committed strays from earlier suites can survive in CI's shared --reuse-db
+ # database, and pagination pages over whatever exists.
+ expected_ids = sorted(str(oid) for oid in Organization.objects.values_list("id", flat=True))
first_page = _get_org_batch_page(
OrgBatchPageInput(workflow_input=WADigestNotificationInput(batch_size=2), page_size=2)
diff --git a/products/web_analytics/backend/test/test_weekly_digest_activities.py b/products/web_analytics/backend/test/test_weekly_digest_activities.py
index 7156ec5622c7..160076ab995c 100644
--- a/products/web_analytics/backend/test/test_weekly_digest_activities.py
+++ b/products/web_analytics/backend/test/test_weekly_digest_activities.py
@@ -374,9 +374,12 @@ class TestGetOrgBatchPage(APIBaseTest):
assert page.cursor is None
def test_keyset_pagination_returns_first_middle_and_final_pages(self):
- orgs = [self.organization]
- orgs.extend(Organization.objects.create(name=f"Org {i}") for i in range(4))
- expected_ids = sorted(str(org.id) for org in orgs)
+ for i in range(4):
+ Organization.objects.create(name=f"Org {i}")
+ # Expected ids come from the database rather than just the orgs created above:
+ # committed strays from earlier suites can survive in CI's shared --reuse-db
+ # database, and pagination pages over whatever exists.
+ expected_ids = sorted(str(oid) for oid in Organization.objects.values_list("id", flat=True))
first_page = _get_org_batch_page(
OrgBatchPageInput(
@@ -387,25 +390,20 @@ class TestGetOrgBatchPage(APIBaseTest):
assert [oid for batch in first_page.batches for oid in batch] == expected_ids[:2]
assert first_page.cursor == expected_ids[1]
- middle_page = _get_org_batch_page(
- OrgBatchPageInput(
- workflow_input=WAWeeklyDigestInput(active_since_days=None, batch_size=2),
- cursor=first_page.cursor,
- page_size=2,
+ final_ids: list[str] = []
+ cursor: str | None = first_page.cursor
+ while cursor is not None:
+ page = _get_org_batch_page(
+ OrgBatchPageInput(
+ workflow_input=WAWeeklyDigestInput(active_since_days=None, batch_size=2),
+ cursor=cursor,
+ page_size=2,
+ )
)
- )
- assert [oid for batch in middle_page.batches for oid in batch] == expected_ids[2:4]
- assert middle_page.cursor == expected_ids[3]
+ final_ids.extend(oid for batch in page.batches for oid in batch)
+ cursor = page.cursor
- final_page = _get_org_batch_page(
- OrgBatchPageInput(
- workflow_input=WAWeeklyDigestInput(active_since_days=None, batch_size=2),
- cursor=middle_page.cursor,
- page_size=2,
- )
- )
- assert [oid for batch in final_page.batches for oid in batch] == expected_ids[4:]
- assert final_page.cursor is None
+ assert expected_ids[:2] + final_ids == expected_ids
def test_active_since_filter_excludes_orgs_with_only_dormant_members(self):
self.user.last_login = timezone.now()