: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): add five Factorial lookup and attrition tables (#107691)
Tom Owers28c8b75d8447
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.mdindex 2e3d4ea358cc..85feb4e92383 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md@@ -2993,7 +2993,7 @@ Note: Endpoint list extracted from the \*.api URLs on the developers page. Also## Factorial — **thin**-Today (21): `allowance_stats`, `allowances`, `applications`, `attendance_shifts`, `candidates`, `compensations`, `contract_versions`, `employees`, `expenses`, `flexible_time_records`, `job_postings`, `leave_types`, `leaves`, `legal_entities`, `locations`, `payroll_supplements`, `projects`, `team_memberships`, `teams`, `time_records`, `worked_times`+Today (26): `allowance_stats`, `allowances`, `application_phases`, `applications`, `attendance_shifts`, `candidate_sources`, `candidates`, `compensations`, `contract_versions`, `cost_centers`, `employees`, `expenses`, `flexible_time_records`, `hiring_stages`, `job_postings`, `leave_types`, `leaves`, `legal_entities`, `locations`, `payroll_supplements`, `projects`, `team_memberships`, `teams`, `terminations`, `time_records`, `worked_times`Diffed against: <https://apidoc.factorialhr.com/reference>@@ -3001,16 +3001,16 @@ Diffed against: <https://apidoc.factorialhr.com/reference>- [x] `project_management/time_records` — time booked against projects; projects are synced but the time booked to them is not (high)- [x] `contracts/compensations` — salary and compensation amounts attached to contract versions we already sync (high)- [x] `timeoff/allowance_stats` — consumed vs remaining balance per employee and allowance - the number leave reporting actually needs (high)-- [ ] `ats/hiring_stages and ats/application_phases` — lookup tables resolving the stage/phase id carried on every synced application (high)-- [ ] `finance/cost_centers` — lookup table for cost allocation across employees, expenses and projects (high)-- [ ] `employee_updates/terminations` — attrition events with dates and reasons; headcount churn is not derivable from the employees snapshot (high)+- [x] `ats/hiring_stages and ats/application_phases` — lookup tables resolving the stage/phase id carried on every synced application (high)+- [x] `finance/cost_centers` — lookup table for cost allocation across employees, expenses and projects (high)+- [x] `employee_updates/terminations` — attrition events with dates and reasons; headcount churn is not derivable from the employees snapshot (high)- [ ] `employee_updates/new_hires` — hire events for headcount growth and time-to-start reporting (medium)- [ ] `finance/cost_center_memberships` — employee-to-cost-center membership needed to attribute cost (medium)-- [ ] `ats/candidate_sources` — lookup resolving the source id on candidates; source-of-hire is a core recruiting breakdown (medium)+- [x] `ats/candidate_sources` — lookup resolving the source id on candidates; source-of-hire is a core recruiting breakdown (medium)- [ ] `attendance/overtime_requests` — overtime volume and approval state per employee (medium)- [ ] `job_catalog/roles and job_catalog/levels` — lookup tables for role and level ids used in compensation banding (medium)-Note: The reference exposes roughly 140 list endpoints across ATS, attendance, contracts, finance, payroll, performance, procurement, project management, time off, trainings and work schedules; PostHog covers 17. Other notable untapped families: performance review evaluations/scores, banking transactions, finance journal entries/lines, procurement purchase orders, trainings sessions/attendances, shift management, custom field values. The docs hub is readme.io with no downloadable OpenAPI - the resource list was read off the /reference sidebar route slugs (api-2026-07-01).+Note: The reference exposes roughly 140 list endpoints across ATS, attendance, contracts, finance, payroll, performance, procurement, project management, time off, trainings and work schedules; PostHog covers 26. Other notable untapped families: performance review evaluations/scores, banking transactions, finance journal entries/lines, procurement purchase orders, trainings sessions/attendances, shift management, custom field values. The docs hub is readme.io with no downloadable OpenAPI - the resource list was read off the /reference sidebar route slugs (api-2026-07-01).## Fastly — **thin**diff --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 ef107092b8cc..ebc43f5ee98c 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@@ -49,12 +49,15 @@ Source-local notes for the Factorial (HRIS) connector. See the official referenc`subprojects` to incremental once the filter is verified against a live account with a future-date cutoff.- For genuine change tracking, Factorial also exposes `employee_updates/*` change-feed resources and webhooks(`api_public/webhook_subscriptions`) — candidates for a future webhook-backed iteration.+- `employee_updates/terminations` is such a change feed, but it carries no timestamp column at all (not even+ `created_at`), so it syncs full refresh like everything else.## Synced endpoints (`settings.py`)| Table | Path | Partition key || --------------------- | ----------------------------------------------------- | ------------- || employees | `/resources/employees/employees` | created_at |+| terminations | `/resources/employee_updates/terminations` | — || teams | `/resources/teams/teams` | — || team_memberships | `/resources/teams/memberships` | — || locations | `/resources/locations/locations` | — |@@ -68,6 +71,7 @@ Source-local notes for the Factorial (HRIS) connector. See the official referenc| attendance_shifts | `/resources/attendance/shifts` | created_at || worked_times | `/resources/attendance/worked_times` | — || expenses | `/resources/expenses/expenses` | created_at |+| cost_centers | `/resources/finance/cost_centers` | — || payroll_supplements | `/resources/payroll/supplements` | created_at || flexible_time_records | `/resources/project_management/flexible_time_records` | created_at || time_records | `/resources/project_management/time_records` | — |@@ -75,6 +79,9 @@ Source-local notes for the Factorial (HRIS) connector. See the official referenc| candidates | `/resources/ats/candidates` | created_at || job_postings | `/resources/ats/job_postings` | — || applications | `/resources/ats/applications` | created_at |+| application_phases | `/resources/ats/application_phases` | — |+| hiring_stages | `/resources/ats/hiring_stages` | — |+| candidate_sources | `/resources/ats/candidate_sources` | — |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@@ -100,6 +107,17 @@ and `time_records` on its own record id. Partition keys are `created_at` where tfor everyone else the endpoint is a permission failure, which `get_non_retryable_errors` already maps.- **`contracts/compensations`** holds the salary and pay-concept lines hanging off a `contract_version_id`we already sync. `amount` is in the smallest currency unit.+- **`ats/hiring_stages`** is the fixed pipeline ladder (`new` → `screening` → `interview` → `assessment` →+ `offer` → `hired`) that every job posting's `ats/application_phases` map onto through `ats_hiring_stage_id`.+ The two together resolve the phase and stage ids carried on each synced application.+- **`ats/candidate_sources`** resolves the source id on a candidate into a name and a category+ (`job_board`, `agency_or_external_recruiter`, `event`, `social_media`, `referral`, …), which is what+ source-of-hire reporting breaks down by.+- **`finance/cost_centers`** is the cost allocation lookup. It carries counts of assigned employees but not the+ assignments themselves — those live in `finance/cost_center_memberships`, which is not synced yet.+- **`employee_updates/terminations`** is the attrition feed: one row per leaver with `terminated_on`,+ `contract_end_date` and the termination reason. The `employees` snapshot carries only the current state of+ each person, so headcount churn over time is not derivable from it.- **`timeoff/allowance_stats`** is a computed snapshot, not a stored record: it recalculates against a`reference_date` that defaults to today, so each full-refresh sync replaces the table with the balances asof that run. Its `id` embeds the reference date and the docs state it cannot be used to re-fetch the row.@@ -109,9 +127,12 @@ and `time_records` on its own record id. Partition keys are `created_at` where t## Verification statusEndpoint paths, pagination, and the `updated_after` coverage were cross-referenced against the official docs-and the Airbyte/Fivetran connector stream lists. The four endpoints added most recently — `worked_times`,-`time_records`, `compensations`, `allowance_stats` — were checked against the OpenAPI document the reference-site serves for `2026-07-01` and `2026-04-01`: each is a GET list route returning the-`{"meta": _paged_index_meta, "data": [...]}` envelope, so they page exactly like the existing tables. They were **not** curl-verified against a live account (no+and the Airbyte/Fivetran connector stream lists. The endpoints added since the initial set — `worked_times`,+`time_records`, `compensations`, `allowance_stats`, and then `terminations`, `cost_centers`,+`application_phases`, `hiring_stages`, `candidate_sources` — were checked against the OpenAPI document the+reference site serves for `2026-07-01` and `2026-04-01`: each is a GET list route returning the+`{"meta": _paged_index_meta, "data": [...]}` envelope, so they page exactly like the existing tables. The five+lookup/change-feed resources take only optional id filters, so they need no static params, and none of them+carries a `created_at` column, so none is partitioned. They were **not** curl-verified against a live account (noAPI key available). The connection (host, version path, `x-api-key`, 401-on-bad-key) was confirmed with anunauthenticated curl returning `401`.diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/canonical_descriptions.pyindex b33dea31cd70..0b286fdfccc4 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/factorial/canonical_descriptions.py@@ -33,6 +33,23 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"updated_at": "Time at which the employee record was last updated.",},},+ "terminations": {+ "description": "Termination events for employees who left the company, with the leaving date and reason.",+ "docs_url": _DOCS,+ "columns": {+ "id": "Unique identifier for the termination.",+ "status": "Status of the termination, such as `to-do` or `done`.",+ "employee_id": "Identifier of the employee being terminated.",+ "terminated_on": "Date the employee was terminated.",+ "contract_end_date": "Date the employment contract ends. The employee can still have access to Factorial after this date.",+ "termination_reason": "Reason recorded for the termination.",+ "termination_reason_type": "Category of the termination reason, such as `company` or `employee`.",+ "termination_type_description": "Description of the termination type.",+ "termination_observations": "Free-text observations about the termination.",+ "legal_entity_id": "Identifier of the legal entity the employee belonged to.",+ "remaining_holidays": "Leave balances the employee still had when they left.",+ },+ },"teams": {"description": "Teams used to group employees within the company.","docs_url": _DOCS,@@ -219,6 +236,22 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"updated_at": "Time at which the expense was last updated.",},},+ "cost_centers": {+ "description": "Cost centers used to allocate employee, expense and project costs within the company.",+ "docs_url": _DOCS,+ "columns": {+ "id": "Unique identifier for the cost center.",+ "name": "Name of the cost center.",+ "code": "Code the company uses to reference the cost center in its accounting.",+ "description": "Description of the cost center.",+ "company_id": "Identifier of the company the cost center belongs to.",+ "legal_entity_id": "Identifier of the legal entity the cost center belongs to.",+ "active_employees_count": "Number of employees currently assigned to the cost center.",+ "historical_employees_count": "Number of employees ever assigned to the cost center.",+ "status": "Whether the cost center is active or deactivated.",+ "deactivation_date": "Date the cost center was deactivated, if applicable.",+ },+ },"payroll_supplements": {"description": "Payroll supplements (one-off additions or deductions applied to payroll).","docs_url": _DOCS,@@ -302,4 +335,41 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"updated_at": "Time at which the application was last updated.",},},+ "application_phases": {+ "description": "Phases of the hiring pipeline for a job posting, that applications move through.",+ "docs_url": _DOCS,+ "columns": {+ "id": "Unique identifier for the application phase.",+ "ats_job_posting_id": "Identifier of the job posting the phase belongs to.",+ "ats_hiring_stage_id": "Identifier of the hiring stage the phase maps to.",+ "name": "Name of the application phase.",+ "phase_type": "Type of the phase, such as `initial`, `interview` or `hired`.",+ "position": "Order of the phase in the job posting's pipeline.",+ "editable": "Whether the phase can be edited.",+ "applications_count": "Number of applications in the phase.",+ "active_applications_count": "Number of active applications in the phase.",+ },+ },+ "hiring_stages": {+ "description": "Standard hiring stages the application phases of every job posting map onto.",+ "docs_url": _DOCS,+ "columns": {+ "id": "Unique identifier for the hiring stage.",+ "name": "Name of the hiring stage, such as `screening`, `interview` or `hired`.",+ "label": "Display label of the hiring stage.",+ "company_id": "Identifier of the company the hiring stage belongs to.",+ "position": "Order of the hiring stage in the pipeline.",+ },+ },+ "candidate_sources": {+ "description": "Sources candidates come from, used for source-of-hire reporting.",+ "docs_url": _DOCS,+ "columns": {+ "id": "Unique identifier for the candidate source.",+ "company_id": "Identifier of the company the source belongs to.",+ "category": "Category of the source, such as `job_board`, `referral` or `social_media`.",+ "name": "Name of the source.",+ "label": "Display label of the source, translated for Factorial's default sources.",+ },+ },}diff --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 99fb09b5b1e1..d3f1320dbda4 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@@ -26,14 +26,19 @@ 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 `id`.+# connectors: people & org structure, employee change events, contracts, time off, attendance,+# expenses, cost allocation, payroll, project time tracking, and recruiting (ATS). Every list+# resource is keyed by a unique `id`.FACTORIAL_ENDPOINTS: dict[str, FactorialEndpointConfig] = {"employees": FactorialEndpointConfig(name="employees",path="/resources/employees/employees",partition_key="created_at",),+ "terminations": FactorialEndpointConfig(+ name="terminations",+ path="/resources/employee_updates/terminations",+ ),"teams": FactorialEndpointConfig(name="teams",path="/resources/teams/teams",@@ -95,6 +100,10 @@ FACTORIAL_ENDPOINTS: dict[str, FactorialEndpointConfig] = {path="/resources/expenses/expenses",partition_key="created_at",),+ "cost_centers": FactorialEndpointConfig(+ name="cost_centers",+ path="/resources/finance/cost_centers",+ ),"payroll_supplements": FactorialEndpointConfig(name="payroll_supplements",path="/resources/payroll/supplements",@@ -127,6 +136,18 @@ FACTORIAL_ENDPOINTS: dict[str, FactorialEndpointConfig] = {path="/resources/ats/applications",partition_key="created_at",),+ "application_phases": FactorialEndpointConfig(+ name="application_phases",+ path="/resources/ats/application_phases",+ ),+ "hiring_stages": FactorialEndpointConfig(+ name="hiring_stages",+ path="/resources/ats/hiring_stages",+ ),+ "candidate_sources": FactorialEndpointConfig(+ name="candidate_sources",+ path="/resources/ats/candidate_sources",+ ),}ENDPOINTS = tuple(FACTORIAL_ENDPOINTS.keys())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 ff43f135aa48..d76d9f348a4b 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@@ -70,10 +70,11 @@ class TestFactorialSource:assert leaves["sync_methods"] == ["Full refresh"]assert leaves["primary_keys"] == [] # detected_primary_keys is unset for static schemas- def test_canonical_descriptions_keyed_by_endpoint(self) -> None:+ def test_canonical_descriptions_cover_every_endpoint(self) -> None:descriptions = self.source.get_canonical_descriptions()- # Every documented table must map to a real endpoint, else the description is dead weight.- assert set(descriptions).issubset(set(ENDPOINTS))+ # A description keyed to no endpoint is dead weight, and an endpoint with no description+ # ships to the public docs with an LLM-guessed table summary instead of the vendor's.+ assert set(descriptions) == set(ENDPOINTS)@pytest.mark.parametrize(("mock_return", "expected_valid", "expected_message"),