: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
feat(warehouse_sources): deprecate Factorial API version 2025-04-01 (#101529)
Tom Owers9e80d99ee742
diff --git a/.agents/skills/warehouse-source-new-version/SKILL.md b/.agents/skills/warehouse-source-new-version/SKILL.mdindex 55a816ea13b3..fa75d01ccb11 100644--- a/.agents/skills/warehouse-source-new-version/SKILL.md+++ b/.agents/skills/warehouse-source-new-version/SKILL.md@@ -71,7 +71,7 @@ version sunset - confirm the version itself stops being served before deprecatin2. Add the old version to `deprecated_versions` with the vendor's announced sunset date (or `sunset_at=None` if none). Never deprecate `default_version` — flip the default to the new version in the same PR.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.-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. Do not execute migrations or backfills; humans review and run them.+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.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/0164_repin_factorial_api_version.py b/products/warehouse_sources/backend/migrations/0164_repin_factorial_api_version.pynew file mode 100644index 000000000000..839ad91eba80--- /dev/null+++ b/products/warehouse_sources/backend/migrations/0164_repin_factorial_api_version.py@@ -0,0 +1,45 @@+from django.db import migrations++# Factorial serves each quarterly version for one year, so "2025-04-01" stopped being served on+# 2026-04-01. A request on a retired version is not rejected — Factorial serves it "using the oldest+# version schema" instead — so a pin left behind moves silently rather than failing loudly, which is+# exactly what the pinning framework exists to prevent. This repins source-level pins from+# "2025-04-01" to "2026-07-01" (the current default).+#+# No data or schema transform accompanies the repin. The versions differ only in that "2026-07-01"+# serializes resource ids as opaque strings: the paths, the pagination cursor, and the response+# envelope are unchanged, the primary key stays the auto-inferred `id` column, and every Factorial+# schema is full refresh, so the next scheduled sync drops the table and rebuilds it under the new+# inferred types.+FACTORIAL_SOURCE_TYPE = "Factorial"+FACTORIAL_API_VERSION_2025_04_01 = "2025-04-01"+FACTORIAL_API_VERSION_2026_07_01 = "2026-07-01"+++def repin_factorial_2025_04_01_to_2026_07_01(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-07-01"), so they need no+ # update, and "2026-04-01" pins are still served by Factorial and stay put. Matching only+ # `api_version="2025-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=FACTORIAL_SOURCE_TYPE, api_version=FACTORIAL_API_VERSION_2025_04_01+ ).update(api_version=FACTORIAL_API_VERSION_2026_07_01)+++class Migration(migrations.Migration):+ dependencies = [+ ("warehouse_sources", "0163_externaldataschema_auto_disabled_at"),+ ]++ operations = [+ # Reverse is a no-op: once repinned, "2026-07-01" rows are indistinguishable from+ # natively-created ones, so a blanket downgrade would clobber legitimate "2026-07-01" pins+ # and move customers back onto the sunset version.+ migrations.RunPython(repin_factorial_2025_04_01_to_2026_07_01, migrations.RunPython.noop, elidable=True),+ ]diff --git a/products/warehouse_sources/backend/migrations/max_migration.txt b/products/warehouse_sources/backend/migrations/max_migration.txtindex d7f5f8752a79..c19bad42fc65 100644--- a/products/warehouse_sources/backend/migrations/max_migration.txt+++ b/products/warehouse_sources/backend/migrations/max_migration.txt@@ -1 +1 @@-0163_externaldataschema_auto_disabled_at+0164_repin_factorial_api_versiondiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/api_inventory.md b/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/api_inventory.mdindex 68d976455c66..c91da9cd6eda 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/api_inventory.md+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/api_inventory.md@@ -11,6 +11,12 @@ Source-local notes for the Factorial (HRIS) connector. See the official referencbase URL in `factorial.py`. Resources occasionally move between groups across versions, but the resourcepaths and the `{"meta": ..., "data": [...]}` envelope our reads use are identical across all three labels(newer versions only add/remove response fields, which the auto-inferred schema absorbs).+- **Version lifecycle:** Factorial ships a version at the start of each quarter and serves each for one+ year. A request on a retired version is not rejected — it is served "using the oldest version schema" —+ so a stale pin drifts silently instead of failing. `2025-04-01` passed its window on 2026-04-01 and is+ marked deprecated in `source.py`; migration `0164_repin_factorial_api_version` repins source-level pins+ to `2026-07-01`. Because the vendor falls forward rather than erroring, there is no version-rejection+ status to add to `get_non_retryable_errors`.- **Identifier serialization:** `2026-07-01` ("Bessel") serializes every resource id as an opaque stringinstead of an integer (ids outgrew the safe 64-bit range) — in request params, responses, and webhooks.Our reads tolerate this without a version branch: the primary key stays the `id` column (type-agnostic,@@ -64,8 +70,10 @@ Source-local notes for the Factorial (HRIS) connector. See the official referenc| job_postings | `/resources/ats/job_postings` | — || applications | `/resources/ats/applications` | created_at |-Primary key is the integer `id` on every list resource. Partition keys are `created_at` where the field is-reliably present on every row (transactional records); lookup/config resources are left unpartitioned.+Primary key is the `id` column on every list resource. It is serialized as an integer on `2025-04-01` and+`2026-04-01`, and as an opaque string on `2026-07-01` (see Identifier serialization above), so the column type is+left to inference. Partition keys are `created_at` where the field is reliably present on every row+(transactional records); lookup/config resources are left unpartitioned.## Rate limitsdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/settings.pyindex df47d8b00d48..c891e1abbe24 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/settings.py@@ -21,7 +21,7 @@ class FactorialEndpointConfig:# A focused, canonical HRIS stream set cross-referenced against the Airbyte/Fivetran Factorial# connectors: people & org structure, contracts, time off, attendance, expenses, payroll, project-# time tracking, and recruiting (ATS). Every list resource is keyed by a unique integer `id`.+# time tracking, and recruiting (ATS). Every list resource is keyed by a unique `id`.FACTORIAL_ENDPOINTS: dict[str, FactorialEndpointConfig] = {"employees": FactorialEndpointConfig(name="employees",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/source.pyindex e015b8596721..ced310d66bf7 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/source.py@@ -1,3 +1,4 @@+from datetime import datefrom typing import Optional, castfrom products.warehouse_sources.backend.facade.source_config import (@@ -7,7 +8,11 @@ from products.warehouse_sources.backend.facade.source_config import (SourceFieldInputConfig,SourceFieldInputConfigType,)-from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import FieldType, ResumableSource+from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import (+ FieldType,+ ResumableSource,+ VersionDeprecation,+)from products.warehouse_sources.backend.temporal.data_imports.sources.common.canonical_descriptions import (CanonicalDescriptions,)@@ -40,6 +45,10 @@ class FactorialSource(ResumableSource[FactorialSourceConfig, FactorialResumeConfsupported_versions = (API_VERSION_2025_04_01, API_VERSION_2026_04_01, API_VERSION_2026_07_01)default_version = API_VERSION_2026_07_01api_docs_url = "https://apidoc.factorialhr.com/docs/api-versioning"+ # Factorial serves each quarterly version for one year, then silently serves the oldest+ # supported schema instead of rejecting the request — so `2025-04-01` stopped being honored on+ # 2026-04-01 with no failed sync to surface it.+ deprecated_versions = (VersionDeprecation(version=API_VERSION_2025_04_01, sunset_at=date(2026, 4, 1)),)@propertydef source_type(self) -> ExternalDataSourceType:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/tests/test_factorial_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/tests/test_factorial_source.pyindex da8d95294082..ff43f135aa48 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/tests/test_factorial_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/tests/test_factorial_source.py@@ -1,3 +1,4 @@+from datetime import datefrom typing import Anyimport pytest@@ -131,3 +132,23 @@ class TestFactorialSource:resumable_source_manager=manager,api_version=resolved,)+++class TestFactorialVersionDeprecation:+ def setup_method(self) -> None:+ self.source = FactorialSource()++ def test_2025_04_01_is_deprecated_with_sunset_date(self) -> None:+ # The generic in-product warning keys off this metadata; the registry invariant test checks+ # the set relationships but not the specific sunset date this PR pins.+ deprecation = self.source.get_version_deprecation("2025-04-01")+ assert deprecation is not None+ assert deprecation.sunset_at == date(2026, 4, 1)++ @pytest.mark.parametrize("version", ["2026-04-01", "2026-07-01"])+ def test_still_served_versions_are_not_deprecated(self, version: str) -> None:+ assert self.source.get_version_deprecation(version) is None++ def test_unpinned_source_is_not_deprecated(self) -> None:+ # An unpinned row resolves to the default, which must never carry a deprecation warning.+ assert self.source.get_version_deprecation(None) is None