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.

fix(flags): degrade group-type lookups when personhog is unconfigured (#70577)

posthog[bot]b9ddb01bc733
diff --git a/posthog/models/group_type_mapping.py b/posthog/models/group_type_mapping.py
index 42cb1b36bf7c..dd89cfba76c2 100644
--- a/posthog/models/group_type_mapping.py
+++ b/posthog/models/group_type_mapping.py
@@ -198,8 +198,7 @@ def get_group_types_for_project(project_id: int, *, caller_tag: str | None = Non
def _fetch() -> list[dict[str, Any]]:
# require_personhog_client() must run inside personhog_call so a missing client
# (RuntimeError) is wrapped as DatabaseError and recovered like any fetch failure.
- client = require_personhog_client()
- return _fetch_group_types_via_personhog(client, project_id)
+ return _fetch_group_types_via_personhog(require_personhog_client(), project_id)
try:
result = personhog_call(
@@ -243,8 +242,7 @@ def get_group_types_for_team(team_id: int, *, caller_tag: str | None = None) ->
def _fetch() -> list[dict[str, Any]]:
# require_personhog_client() must run inside personhog_call so a missing client
# (RuntimeError) is wrapped as DatabaseError and recovered like any fetch failure.
- client = require_personhog_client()
- return _fetch_group_types_for_team_via_personhog(client, team_id)
+ return _fetch_group_types_for_team_via_personhog(require_personhog_client(), team_id)
try:
return personhog_call(
@@ -480,10 +478,9 @@ def count_group_type_mappings_per_team(*, caller_tag: str | None = None) -> list
def _fetch() -> list[dict[str, int]]:
# require_personhog_client() must run inside personhog_call so a missing client
# (RuntimeError) is wrapped as DatabaseError and recovered like any fetch failure.
- client = require_personhog_client()
return [
{"team_id": c.team_id, "total": c.count}
- for c in client.count_group_type_mappings(CountGroupTypeMappingsRequest()).counts
+ for c in require_personhog_client().count_group_type_mappings(CountGroupTypeMappingsRequest()).counts
]
try:
diff --git a/posthog/models/test/test_group_type_mapping.py b/posthog/models/test/test_group_type_mapping.py
index d9f2b0dd0f4c..39ded6e834b7 100644
--- a/posthog/models/test/test_group_type_mapping.py
+++ b/posthog/models/test/test_group_type_mapping.py
@@ -120,6 +120,14 @@ class TestGetGroupTypesForProject(SimpleTestCase):
assert result == stale_data
+ def test_unconfigured_client_falls_back_instead_of_raising(self):
+ # Worker without PERSONHOG_ADDR: require_personhog_client() raises RuntimeError.
+ # It must reach the DatabaseError fallback, not escape and crash the caller.
+ with patch(_CLIENT_PATCH, return_value=None):
+ result = get_group_types_for_project(self.project_id)
+
+ assert result == []
+
class TestGetGroupTypesForTeam(SimpleTestCase):
def setUp(self):
@@ -155,6 +163,12 @@ class TestGetGroupTypesForTeam(SimpleTestCase):
assert result == []
+ def test_unconfigured_client_returns_empty_instead_of_raising(self):
+ with patch(_CLIENT_PATCH, return_value=None):
+ result = get_group_types_for_team(self.team_id)
+
+ assert result == []
+
class TestGetGroupTypesForProjects(SimpleTestCase):
def setUp(self):
@@ -477,6 +491,12 @@ class TestCountGroupTypeMappingsPerTeam(SimpleTestCase):
assert result == []
+ def test_unconfigured_client_returns_empty_instead_of_raising(self):
+ with patch(_CLIENT_PATCH, return_value=None):
+ result = count_group_type_mappings_per_team()
+
+ assert result == []
+
# ── Write helper tests ─────────────────────────────────────────────