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(data-warehouse): record sync frequency changes on tiered teams (#77595)

Jovan Sakovic655a2806e19a
diff --git a/products/data_warehouse/backend/presentation/views/saved_query.py b/products/data_warehouse/backend/presentation/views/saved_query.py
index dacb0578fa60..ca628f9f22f6 100644
--- a/products/data_warehouse/backend/presentation/views/saved_query.py
+++ b/products/data_warehouse/backend/presentation/views/saved_query.py
@@ -698,11 +698,13 @@ class DataWarehouseSavedQuerySerializer(
UnsatisfiableFrequencyError,
UnsupportedFrequencyTargetError,
apply_saved_query_frequency_target,
+ declared_targets_by_saved_query,
)
target = (
None if sync_frequency == "never" else sync_frequency_to_sync_frequency_interval(sync_frequency)
)
+ previous_target = declared_targets_by_saved_query(view.team_id, [view.pk]).get(str(view.pk))
try:
# Validates inside the transaction (a rejected frequency rolls the whole
# update back) and queues the schedule reconcile for after commit.
@@ -766,6 +768,18 @@ class DataWarehouseSavedQuerySerializer(
)
for change in changes
]
+ if dag_managed_frequency and previous_target != target:
+ # The cadence lives on the DAG node, so changes_between() sees nothing and
+ # log_activity would discard the whole updated entry as a no-op.
+ changes.append(
+ Change(
+ type="DataWarehouseSavedQuery",
+ action="changed",
+ field="sync_frequency_interval",
+ before=str(previous_target) if previous_target is not None else None,
+ after=str(target) if target is not None else None,
+ )
+ )
activity_log = log_activity(
organization_id=team.organization_id,
team_id=team.id,
diff --git a/products/data_warehouse/backend/tests/api/test_saved_query.py b/products/data_warehouse/backend/tests/api/test_saved_query.py
index 6631085cdc35..662bac0427e8 100644
--- a/products/data_warehouse/backend/tests/api/test_saved_query.py
+++ b/products/data_warehouse/backend/tests/api/test_saved_query.py
@@ -827,6 +827,47 @@ class TestSavedQuery(APIBaseTest):
# a stale v1 schedule from a half-finished migration must not be revived by the PATCH
v1_exists.assert_not_called()
+ @parameterized.expand(
+ [
+ ("24hour", "12:00:00", "1 day, 0:00:00"),
+ ("never", "12:00:00", None),
+ ]
+ )
+ def test_sync_frequency_change_on_tiered_v2_is_recorded_in_the_activity_log(
+ self, sync_frequency: str, expected_before: str, expected_after: str | None
+ ):
+ # a tiered team stores the cadence on the DAG node and keeps the interval column NULL, so a
+ # frequency edit changes no model field — changes_between() returns nothing and log_activity
+ # drops an "updated" entry with no changes, leaving the edit with no audit trail at all
+ from products.data_modeling.backend.logic.node_frequency import set_declared_target
+ from products.data_modeling.backend.models import Node
+
+ saved_query = self._create_saved_query_for_frequency_tests()
+ node = Node.objects.get(saved_query_id=saved_query["id"])
+ set_declared_target(node, timedelta(hours=12))
+ reconcile_module = "products.data_modeling.backend.logic.schedule_reconcile"
+
+ with (
+ patch(
+ "products.data_warehouse.backend.presentation.views.saved_query.posthoganalytics.feature_enabled",
+ side_effect=self._v2_flag_only,
+ ),
+ patch(f"{reconcile_module}.tiered_schedules_enabled", return_value=True),
+ patch(f"{reconcile_module}.maybe_reconcile_dag"),
+ ):
+ response = self.client.patch(
+ f"/api/environments/{self.team.id}/warehouse_saved_queries/{saved_query['id']}",
+ {"sync_frequency": sync_frequency},
+ )
+
+ self.assertEqual(response.status_code, 200, response.json())
+ log = ActivityLog.objects.get(scope="DataWarehouseSavedQuery", item_id=saved_query["id"], activity="updated")
+ detail = cast(dict[str, Any], log.detail)
+ frequency_changes = [change for change in detail["changes"] if change["field"] == "sync_frequency_interval"]
+ self.assertEqual(len(frequency_changes), 1, detail["changes"])
+ self.assertEqual(frequency_changes[0]["before"], expected_before)
+ self.assertEqual(frequency_changes[0]["after"], expected_after)
+
def test_update_sync_frequency_on_tiered_v2_without_node_is_rejected(self):
from products.data_modeling.backend.models import Node