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.

feat(data-modeling): generate warehouse suggestions for all eligible teams (#129496)

Thiago Salvatorecab7ae9bbab2
diff --git a/products/warehouse_suggestions/backend/logic/assignment.py b/products/warehouse_suggestions/backend/logic/assignment.py
index ca76b9e9fd0a..e2abee96bbbf 100644
--- a/products/warehouse_suggestions/backend/logic/assignment.py
+++ b/products/warehouse_suggestions/backend/logic/assignment.py
@@ -23,6 +23,7 @@ from ..facade.enums import WarehouseSuggestionKind, WarehouseSuggestionStatus, W
from ..models import WarehouseSuggestion
from .access import CATALOG_KINDS, can_take
from .candidates.base import CandidateContext
+from .flags import is_warehouse_suggestions_enabled
from .payloads import payload_from_json
if TYPE_CHECKING:
@@ -100,6 +101,8 @@ def _assignable_user(team: "Team", suggestion: WarehouseSuggestion, assignee_id:
def notify_surfaced(team: "Team", assigned: Assignments, run_id: str) -> None:
+ if not is_warehouse_suggestions_enabled(team):
+ return
for assignee, rows in assigned.items():
_notify(
team,
diff --git a/products/warehouse_suggestions/backend/temporal/activities.py b/products/warehouse_suggestions/backend/temporal/activities.py
index 1593586631c2..a02900f5ec96 100644
--- a/products/warehouse_suggestions/backend/temporal/activities.py
+++ b/products/warehouse_suggestions/backend/temporal/activities.py
@@ -16,7 +16,6 @@ from posthog.temporal.common.heartbeat import Heartbeater
from posthog.temporal.common.logger import get_logger
from posthog.temporal.common.rollout import filter_ids_for_rollout
-from ..logic.flags import is_warehouse_suggestions_enabled
from ..logic.job import TeamRunStatus, run_team, team_ids_with_suggestions_to_maintain
from ..logic.reads import ReadWindow, read_rollup_days
from ..logic.rules import RULES
@@ -38,14 +37,13 @@ def team_batches(inputs: WarehouseSuggestionsInputs) -> list[list[int]]:
LOGGER.info("warehouse_suggestions.skipped_by_kill_switch")
return []
candidate_ids = inputs.team_ids if inputs.team_ids is not None else _teams_to_run()
- teams = (
+ team_ids = list(
Team.objects.filter(
id__in=candidate_ids, is_demo=False, parent_team__isnull=True, organization__for_internal_metrics=False
)
- .select_related("organization")
.order_by("id")
+ .values_list("id", flat=True)
)
- team_ids = [team.pk for team in teams if is_warehouse_suggestions_enabled(team)]
if inputs.rollout_percentage < FULL_ROLLOUT:
team_ids = filter_ids_for_rollout(team_ids, inputs.rollout_percentage)
return [list(batch) for batch in batched(team_ids, inputs.batch_size, strict=False)]
diff --git a/products/warehouse_suggestions/backend/tests/test_lifecycle.py b/products/warehouse_suggestions/backend/tests/test_lifecycle.py
index 95b8a5938ac5..13d89c5f6dc2 100644
--- a/products/warehouse_suggestions/backend/tests/test_lifecycle.py
+++ b/products/warehouse_suggestions/backend/tests/test_lifecycle.py
@@ -41,6 +41,7 @@ from products.warehouse_suggestions.backend.tests.factories import busy_reads, c
from .test_accept import REPORT
NOTIFY = "products.warehouse_suggestions.backend.logic.assignment.create_notification"
+FLAG = "products.warehouse_suggestions.backend.logic.assignment.is_warehouse_suggestions_enabled"
CAN_TAKE = "products.warehouse_suggestions.backend.logic.assignment.can_take"
NOW = datetime(2026, 10, 7, 9, tzinfo=UTC)
READ_COST_BEFORE = {"read_seconds_per_month": 5000.0, "read_bytes_per_month": 5e12, "human_reads_per_month": 200.0}
@@ -81,6 +82,10 @@ PAYLOADS: dict[WarehouseSuggestionKind, SuggestionPayload] = {
class TestApplyRun(BaseTest):
+ def setUp(self) -> None:
+ super().setUp()
+ self.flag = self.enterContext(patch(FLAG, return_value=True))
+
def _context(self, *view_ids: UUID, recent_days_with_data: int = 7) -> CandidateContext:
return context(
team_reads({}, recent_days_with_data=recent_days_with_data),
@@ -268,11 +273,18 @@ class TestApplyRun(BaseTest):
("creator_who_left_the_organization", "left", WarehouseSuggestionKind.MATERIALIZE, False),
("creator_who_cannot_edit_the_catalog", "catalog_viewer", WarehouseSuggestionKind.CERTIFY, False),
("no_creator", "none", WarehouseSuggestionKind.MATERIALIZE, False),
+ ("creator_on_a_team_without_the_flag", "member", WarehouseSuggestionKind.MATERIALIZE, True, False),
]
)
def test_assigns_surfaced_view_suggestions_to_a_creator_who_can_accept_them(
- self, _name: str, creator_state: str, kind: WarehouseSuggestionKind, expect_assigned: bool
+ self,
+ _name: str,
+ creator_state: str,
+ kind: WarehouseSuggestionKind,
+ expect_assigned: bool,
+ flag_enabled: bool = True,
) -> None:
+ self.flag.return_value = flag_enabled
creator = self._creator(creator_state)
views = [
DataWarehouseSavedQuery.objects.create(
@@ -297,7 +309,7 @@ class TestApplyRun(BaseTest):
expected_assignee = creator.pk if expect_assigned and creator else None
assert (assignee_ids, notified) == (
{expected_assignee},
- [str(expected_assignee)] if expect_assigned else [],
+ [str(expected_assignee)] if expect_assigned and flag_enabled else [],
)
@parameterized.expand([("kept_access_to_the_view", False), ("lost_access_to_the_view", True)])
diff --git a/products/warehouse_suggestions/backend/tests/test_temporal.py b/products/warehouse_suggestions/backend/tests/test_temporal.py
index ad5c88ed57c7..48d11e7e3316 100644
--- a/products/warehouse_suggestions/backend/tests/test_temporal.py
+++ b/products/warehouse_suggestions/backend/tests/test_temporal.py
@@ -41,7 +41,7 @@ class TestTeamBatches(BaseTest):
("kill_switch_on", KillSwitchLevel.LIGHT, False),
]
)
- def test_picks_flagged_main_environments_skips_demo_teams_and_stops_under_the_kill_switch(
+ def test_picks_main_environments_without_the_flag_skips_demo_teams_and_stops_under_the_kill_switch(
self, _name: str, kill_switch: KillSwitchLevel, expect_team: bool
) -> None:
demo_team = Team.objects.create(organization=self.organization, is_demo=True)
@@ -49,11 +49,10 @@ class TestTeamBatches(BaseTest):
child_environment = Team.objects.create(
organization=self.organization, project=self.project, parent_team=self.team
)
- flagged = {self.team.pk, demo_team.pk, child_environment.pk}
with (
patch(f"{ACTIVITIES}.get_kill_switch_level", return_value=kill_switch),
- patch(f"{ACTIVITIES}.is_warehouse_suggestions_enabled", side_effect=lambda team: team.pk in flagged),
+ patch("posthoganalytics.feature_enabled", return_value=False),
):
batches = team_batches(
WarehouseSuggestionsInputs(
@@ -61,7 +60,7 @@ class TestTeamBatches(BaseTest):
)
)
- assert batches == ([[self.team.pk]] if expect_team else [])
+ assert batches == ([[self.team.pk, unflagged_team.pk]] if expect_team else [])
def test_picks_an_idle_team_that_still_has_an_accepted_suggestion(self) -> None:
dismissed_team = Team.objects.create(organization=self.organization)
@@ -82,7 +81,6 @@ class TestTeamBatches(BaseTest):
with (
patch(f"{ACTIVITIES}.get_kill_switch_level", return_value=KillSwitchLevel.OFF),
patch(f"{ACTIVITIES}._teams_with_reads", return_value=[]),
- patch(f"{ACTIVITIES}.is_warehouse_suggestions_enabled", return_value=True),
):
batches = team_batches(WarehouseSuggestionsInputs())