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(warehouse-sources): stop Rokt reports ordering by a non-slug column (#92362)

posthog[bot]e5671f9cdad6
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/rokt_ads/rokt_ads.py b/products/warehouse_sources/backend/temporal/data_imports/sources/rokt_ads/rokt_ads.py
index e482756fce31..13dfc7ed2eef 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/rokt_ads/rokt_ads.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/rokt_ads/rokt_ads.py
@@ -190,13 +190,16 @@ def build_report_body(
if not metrics:
raise RoktAdsError(f"Rokt account grants none of the metrics {endpoint_name} reports on.")
+ # No `orderBys`: the Query API only sorts on a requested dimension or metric slug, and
+ # `datetime` is a response-only interval marker rather than a slug, so ordering by it makes
+ # Rokt reject the whole report with a 400. Row order does not matter here anyway - the
+ # incremental cursor takes the max `datetime` over each window and resume is window-based.
body: dict[str, Any] = {
"interval": REPORT_INTERVAL,
"startDate": window.start.isoformat(),
"endDate": window.end.isoformat(),
"metrics": metrics,
"dimensions": endpoint["dimensions"],
- "orderBys": [{"column": "datetime", "direction": "asc"}],
}
if timezone_variation:
body["timezoneVariation"] = timezone_variation
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/rokt_ads/tests/test_rokt_ads.py b/products/warehouse_sources/backend/temporal/data_imports/sources/rokt_ads/tests/test_rokt_ads.py
index 6bbc06aae2e0..4c7b8bcbf0c4 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/rokt_ads/tests/test_rokt_ads.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/rokt_ads/tests/test_rokt_ads.py
@@ -90,9 +90,12 @@ class TestBuildReportBody:
assert body["startDate"] == "2026-03-01"
assert body["endDate"] == "2026-04-01"
- def test_orders_ascending_so_the_declared_sort_mode_holds(self):
+ def test_does_not_order_by_the_response_only_datetime_field(self):
+ # `datetime` is a response-only interval marker, not a queryable slug, so ordering by it
+ # makes the Query API reject the whole report with a 400.
body = build_report_body("CampaignPerformance", MARCH_WINDOW, ALL_CAPABILITIES, None, None)
- assert body["orderBys"] == [{"column": "datetime", "direction": "asc"}]
+ order_columns = {order["column"] for order in body.get("orderBys", [])}
+ assert "datetime" not in order_columns
def test_drops_metrics_the_account_cannot_report_on(self):
body = build_report_body(