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): repin gusto off sunset api version 2024-04-01 (#113224)

Tom Owers62e235a1b43a
diff --git a/.agents/skills/warehouse-source-new-version/SKILL.md b/.agents/skills/warehouse-source-new-version/SKILL.md
index 2ee0193b469f..9456ba7abb54 100644
--- a/.agents/skills/warehouse-source-new-version/SKILL.md
+++ b/.agents/skills/warehouse-source-new-version/SKILL.md
@@ -72,8 +72,8 @@ The opposite gap also occurs: a reference rendered from one version-blind OpenAP
2. Add the old version to `deprecated_versions` with the vendor's announced sunset date (or `sunset_at=None` if none). When the vendor gives only a month ("supported until January 2027"), use the first day of that month: it is the earliest day the version can stop working, so the warning never comes after the vendor stops serving the version. Never deprecate `default_version` — flip the default to the new version in the same PR.
The version to deprecate is the source label whose wire reads the retired path, which can differ from the vendor label in the request. A source on the unversioned `v1` label that reads a vendor `/v2/...` endpoint deprecates and repins `v1`. Never declare the vendor's old label just to deprecate it: no row is pinned to it, and the repin would match nothing.
3. The in-product warning banner and API fields light up automatically from the metadata — zero per-source UI work.
-4. **Deprecated is not migrated.** Existing pins move only when the vendor has announced the version will stop being served (a sunset/removal date). A deprecation without a sunset date is advisory: mark it, leave every existing pin on it fully supported, and write no migration — repinning working customers off a version the vendor still serves is exactly the silent version move the pinning framework exists to prevent. Two narrow cases still repin under an advisory (`sunset_at=None`) deprecation: the deprecated label resolves to a byte-identical request as the new default (a pure alias — no per-version dispatch — so the repin is not a move), or the vendor already errors on the old version (e.g. `410`/`406`) so leaving pins is worse than moving them. A source that sends a per-version header/URL for a version the vendor still serves is neither — stay advisory. A published fixed support window ("each dated version is supported for N months after release") is an announced sunset: compute `sunset_at` from it, even when that date has already passed, and repin. If the docs do not say how the API answers an expired version, add no rejection signature to `get_non_retryable_errors`.
-5. Only for a sunsetting version: include a **written-not-run** migration script that repins affected `ExternalDataSource` rows (`api_version` column) from the deprecated version to the new one, plus any safe data/schema transforms. It must be idempotent and reviewable, and its reverse must be a no-op — repinned rows are indistinguishable from natively-created ones, so a blanket downgrade would clobber legitimate native pins. Repin only rows explicitly on the deprecated version: when the default is already the target (you are deprecating an old label without flipping the default in this PR), do not also repin NULL pins — they already resolve to the current default, so touching them is redundant churn — and leave other still-served deprecated versions alone. Where migration is lossy or unsafe — including when the new version needs credentials that can't be derived from the stored ones — do not script it: document the manual path in the PR. When only a subset of rows is unsafe (the version diverges for one endpoint that needs a credential others don't), split the cohort: script the repin for the safe rows and exclude the unsafe ones by querying their schemas, documenting only that cohort as manual — don't drop the whole migration to manual because one endpoint can't move. Whether a column whose _type_ changes across the versions needs a transform is decided by the schema's sync type, not by the type change: a full-refresh schema drops its table before every sync, so the next run rebuilds it under the newly inferred types and the repin alone is enough, while a merge-based schema carries the old type forward and needs a `reset_pipeline` stamp (delta-rs cannot widen in place, and the automatic resync covers only safe numeric widenings). Do not execute migrations or backfills; humans review and run them.
+4. **Deprecated is not migrated.** Existing pins move only when the vendor has announced the version will stop being served (a sunset/removal date). A deprecation without a sunset date is advisory: mark it, leave every existing pin on it fully supported, and write no migration — repinning working customers off a version the vendor still serves is exactly the silent version move the pinning framework exists to prevent. Two narrow cases still repin under an advisory (`sunset_at=None`) deprecation: the deprecated label resolves to a byte-identical request as the new default (a pure alias — no per-version dispatch — so the repin is not a move), or the vendor already errors on the old version (e.g. `410`/`406`) so leaving pins is worse than moving them. A source that sends a per-version header/URL for a version the vendor still serves is neither — stay advisory. A published fixed support window ("each dated version is supported for N months after release") is an announced sunset: compute `sunset_at` from it, even when that date has already passed, and repin. If the docs do not say how the API answers an expired version, add no rejection signature to `get_non_retryable_errors`. Before concluding a vendor publishes no sunset date, find its per-version status table (often on an upgrade-guide page, not the versioning-policy page): a policy page that only describes a generic phase-out timeline is not evidence that no date exists.
+5. Only for a sunsetting version: include a **written-not-run** migration script that repins affected `ExternalDataSource` rows (`api_version` column) from the deprecated version to the new one, plus any safe data/schema transforms. It must be idempotent and reviewable, and its reverse must be a no-op — repinned rows are indistinguishable from natively-created ones, so a blanket downgrade would clobber legitimate native pins. Repin only rows explicitly on the deprecated version: when the default is already the target (you are deprecating an old label without flipping the default in this PR), do not also repin NULL pins — they already resolve to the current default, so touching them is redundant churn — and leave other still-served deprecated versions alone. Where migration is lossy or unsafe — including when the new version needs credentials that can't be derived from the stored ones — do not script it: document the manual path in the PR. When only a subset of rows is unsafe (the version diverges for one endpoint that needs a credential others don't), split the cohort: script the repin for the safe rows and exclude the unsafe ones by querying their schemas, documenting only that cohort as manual — don't drop the whole migration to manual because one endpoint can't move. Whether a column whose _type_ changes across the versions needs a transform is decided by the schema's sync type, not by the type change: a full-refresh schema drops its table before every sync, so the next run rebuilds it under the newly inferred types and the repin alone is enough, while a merge-based schema carries the old type forward and needs a `reset_pipeline` stamp (delta-rs cannot widen in place, and the automatic resync covers only safe numeric widenings). A repin that lands after the sunset does not resume syncs on its own: the vendor's rejection was non-retryable and auto-disabled the affected schemas, so say in the PR that they need re-enabling. Do not execute migrations or backfills; humans review and run them.
6. **Never touch `ExternalDataSchema.api_version` overrides** in migration scripts — they are user-managed by design. The schema-level deprecation warning covers them; the user migrates them from the schema's configuration page.
## Pinning semantics (do not break these)
diff --git a/products/warehouse_sources/backend/migrations/0183_repin_gusto_api_version.py b/products/warehouse_sources/backend/migrations/0183_repin_gusto_api_version.py
new file mode 100644
index 000000000000..4c3df53f091c
--- /dev/null
+++ b/products/warehouse_sources/backend/migrations/0183_repin_gusto_api_version.py
@@ -0,0 +1,43 @@
+from django.db import migrations
+
+# Gusto's final sunset for API version "2024-04-01" was 2026-06-15, and every call pinned to it now
+# returns 406. This repins source-level pins from "2024-04-01" to "2026-06-15" (the current default).
+#
+# No data or schema transform accompanies the repin. Both versions call the same `/v1` paths with
+# the same `page`/`per` pagination, and only the `X-Gusto-API-Version` header differs. The changes
+# between them that touch columns this source reads do not need a transform. Gusto renamed
+# `auto_pilot` to `auto_payroll` and changed nested `employee_compensations` amounts from numbers to
+# strings. A renamed column appears as a new column, and nested values land in a JSON column, so
+# no merge-based table gets a column type it cannot widen. `pay_schedules` is full refresh and
+# rebuilds on its next sync.
+GUSTO_SOURCE_TYPE = "Gusto"
+GUSTO_API_VERSION_2024_04_01 = "2024-04-01"
+GUSTO_API_VERSION_2026_06_15 = "2026-06-15"
+
+
+def repin_gusto_2024_04_01_to_2026_06_15(apps, schema_editor):
+ ExternalDataSource = apps.get_model("warehouse_sources", "ExternalDataSource")
+
+ # Source-level pin only. Schema-level `ExternalDataSchema.api_version` overrides are user-managed
+ # (a customer intentionally pinned that schema) and are left alone. The schema-level deprecation
+ # warning prompts the user to migrate those.
+ #
+ # NULL pins already resolve to the source's `default_version` ("2026-06-15"), so they need no
+ # update. Matching only `api_version="2024-04-01"` keeps this idempotent: a second run matches
+ # nothing. ExternalDataSource is one row per configured source, so a single bulk update is quick.
+ ExternalDataSource.objects.filter(source_type=GUSTO_SOURCE_TYPE, api_version=GUSTO_API_VERSION_2024_04_01).update(
+ api_version=GUSTO_API_VERSION_2026_06_15
+ )
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("warehouse_sources", "0182_datawarehousetable_row_count_bigint"),
+ ]
+
+ operations = [
+ # Reverse is a no-op: once repinned, "2026-06-15" rows are indistinguishable from
+ # natively-created ones, so a blanket downgrade would clobber legitimate "2026-06-15" pins
+ # and move customers back onto the sunset version.
+ migrations.RunPython(repin_gusto_2024_04_01_to_2026_06_15, migrations.RunPython.noop, elidable=True),
+ ]
diff --git a/products/warehouse_sources/backend/migrations/max_migration.txt b/products/warehouse_sources/backend/migrations/max_migration.txt
index 6a11f2924db7..1680a5fc534a 100644
--- a/products/warehouse_sources/backend/migrations/max_migration.txt
+++ b/products/warehouse_sources/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0182_datawarehousetable_row_count_bigint
+0183_repin_gusto_api_version
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gusto/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gusto/canonical_descriptions.py
index 91c372705d5a..4a53da52f072 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gusto/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gusto/canonical_descriptions.py
@@ -120,7 +120,8 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"day_1": "First day of the month employees are paid, for semi-monthly schedules.",
"day_2": "Second day of the month employees are paid, for semi-monthly schedules.",
"name": "The name given to the pay schedule.",
- "auto_pilot": "Whether payrolls on this schedule run automatically.",
+ "auto_payroll": "Whether payrolls on this schedule run automatically.",
+ "auto_pilot": "Whether payrolls on this schedule run automatically. Gusto renamed it to auto_payroll in API version 2025-11-15.",
"active": "Whether the pay schedule is currently in use.",
"_company_uuid": "The company this pay schedule belongs to.",
},
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gusto/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gusto/source.py
index db86e46b79ad..743c121426cc 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gusto/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gusto/source.py
@@ -1,3 +1,4 @@
+from datetime import date
from typing import Optional, cast
from products.warehouse_sources.backend.facade.source_config import (
@@ -47,9 +48,9 @@ class GustoSource(ResumableSource[GustoSourceConfig, GustoResumeConfig]):
supported_versions = (GUSTO_API_VERSION_2024_04_01, GUSTO_API_VERSION_2026_06_15)
default_version = GUSTO_API_VERSION_2026_06_15
api_docs_url = "https://docs.gusto.com/embedded-payroll/reference"
- # Gusto gives a deprecated version 12 months of phased support before calls return 406, but
- # publishes no end-of-life date for 2024-04-01 — advisory only, so existing pins are left in place.
- deprecated_versions = (VersionDeprecation(version=GUSTO_API_VERSION_2024_04_01, sunset_at=None),)
+ # Gusto's version upgrade guide lists 2024-04-01 as no longer supported since its final sunset on
+ # 2026-06-15; calls pinned to it now return 406.
+ deprecated_versions = (VersionDeprecation(version=GUSTO_API_VERSION_2024_04_01, sunset_at=date(2026, 6, 15)),)
@property
def source_type(self) -> ExternalDataSourceType:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gusto/tests/test_gusto_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gusto/tests/test_gusto_source.py
index 3b1c73fa243e..83554d9e78b2 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gusto/tests/test_gusto_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gusto/tests/test_gusto_source.py
@@ -1,3 +1,4 @@
+from datetime import date
from typing import Any
import pytest
@@ -39,6 +40,11 @@ class TestGustoSource:
assert self.source.default_version == GUSTO_API_VERSION_2026_06_15
assert self.source.api_docs_url.startswith("https://")
+ def test_older_version_is_deprecated_with_the_vendor_sunset_date(self) -> None:
+ deprecation = self.source.get_version_deprecation(GUSTO_API_VERSION_2024_04_01)
+ assert deprecation is not None and deprecation.sunset_at == date(2026, 6, 15)
+ assert self.source.get_version_deprecation(GUSTO_API_VERSION_2026_06_15) is None
+
@parameterized.expand([(endpoint,) for endpoint in ENDPOINTS])
def test_only_date_filtered_endpoints_are_incremental(self, endpoint: str) -> None:
# Gusto only filters server-side on money-movement check dates; everything else would have