: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
fix(flags): log team metadata fan-out failures (#71640)
Phil Haackc9311efadda8
diff --git a/posthog/tasks/team_metadata.py b/posthog/tasks/team_metadata.pyindex 9b8987d70540..d1147fd92d42 100644--- a/posthog/tasks/team_metadata.py+++ b/posthog/tasks/team_metadata.py@@ -72,15 +72,24 @@ def update_related_teams_metadata_cache_task(organization_id: int | None = None,the signal enqueues a single task no matter how many teams the org or project owns, and eachper-team update runs as its own task so the work spreads across workers."""- if organization_id is not None:- team_ids = Team.objects.filter(organization_id=organization_id).values_list("id", flat=True)- elif project_id is not None:- team_ids = Team.objects.filter(project_id=project_id).values_list("id", flat=True)- else:- return-- for team_id in team_ids:- update_team_metadata_cache_task.delay(team_id)+ try:+ if organization_id is not None:+ team_ids = Team.objects.filter(organization_id=organization_id).values_list("id", flat=True)+ elif project_id is not None:+ team_ids = Team.objects.filter(project_id=project_id).values_list("id", flat=True)+ else:+ return++ for team_id in team_ids:+ update_team_metadata_cache_task.delay(team_id)+ except Exception as e:+ logger.exception(+ "Failed to fan out related team metadata cache refresh",+ organization_id=organization_id,+ project_id=project_id,+ error=str(e),+ )+ raise@shared_task(ignore_result=True, queue=CeleryQueue.DEFAULT.value)diff --git a/posthog/tasks/test/test_team_metadata_signals.py b/posthog/tasks/test/test_team_metadata_signals.pyindex a07b6b96a1ad..072ab64d34da 100644--- a/posthog/tasks/test/test_team_metadata_signals.py+++ b/posthog/tasks/test/test_team_metadata_signals.py@@ -106,6 +106,17 @@ class TestRelatedTeamsMetadataFanoutTask(BaseTest):mock_update.delay.assert_not_called()+ def test_logs_and_reraises_on_failure(self) -> None:+ with (+ patch("posthog.tasks.team_metadata.update_team_metadata_cache_task") as mock_update,+ patch("posthog.tasks.team_metadata.logger") as mock_logger,+ self.assertRaises(Exception),+ ):+ mock_update.delay.side_effect = Exception("broker down")+ update_related_teams_metadata_cache_task(organization_id=self.organization.id)++ mock_logger.exception.assert_called_once()+@override_settings(FLAGS_REDIS_URL="redis://localhost:6379")class TestOrgProjectDeleteCascadesToTeamClear(BaseTest):