: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(mailgun): send the required duration field to the logs api (#115662)
Tom Owers73628f90d8eb
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mailgun/mailgun.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mailgun/mailgun.pyindex 4805473c4486..be1852516067 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mailgun/mailgun.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mailgun/mailgun.py@@ -620,7 +620,15 @@ def _logs_request_body(start: datetime, end: datetime, token: Optional[str]) ->pagination: dict[str, Any] = {"sort": "timestamp:asc", "limit": LOGS_PAGE_SIZE}if token is not None:pagination["token"] = token- return {"start": format_datetime(start), "end": format_datetime(end), "pagination": pagination}+ # The Logs API's request schema marks `duration` required even though it only has an effect+ # (recomputing `start` from `end`) when non-empty, so an empty string satisfies the+ # requirement without overriding the explicit `start` our pagination depends on.+ return {+ "start": format_datetime(start),+ "end": format_datetime(end),+ "duration": "",+ "pagination": pagination,+ }def get_logs_rows(diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mailgun/tests/test_mailgun.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mailgun/tests/test_mailgun.pyindex 76ebde8e6ca6..48e52085dcb2 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mailgun/tests/test_mailgun.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mailgun/tests/test_mailgun.py@@ -536,6 +536,9 @@ class TestLogsRows:bodies = [request.json() for request in result.requests]assert [body["pagination"].get("token") for body in bodies] == [None, "t1", "t2"]assert {(body["start"], body["end"]) for body in bodies} == {(bodies[0]["start"], bodies[0]["end"])}+ # Mailgun's Logs API rejects a request missing `duration` with a 400, even though an+ # empty value has no effect on the explicit `start`/`end` window.+ assert {body["duration"] for body in bodies} == {""}assert {body["pagination"]["sort"] for body in bodies} == {"timestamp:asc"}assert [row["id"] for row in result.rows] == ["e1", "e2", "e3"]assert "@timestamp" not in result.rows[0]