: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): sync hoorayhr leave budgets and public holidays (#111302)
Tom Owersbed1cb9a5f98
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 8c66cc4d6ff8..12ae097a2f95 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@@ -4118,18 +4118,18 @@ Note: Diffed against the machine-readable OpenAPI spec (api-docs.honeycomb.io/ap## HoorayHR — gaps-Today (15): `availability`, `contracts`, `document_categories`, `employment_term_assignments`, `employment_terms`, `entities`, `labels`, `leave_types`, `sick_leave_dossiers`, `sick_leave_phases`, `teams_information`, `time_off`, `time_tracking`, `users`, `work_location_categories`+Today (18): `availability`, `contracts`, `document_categories`, `employment_term_assignments`, `employment_terms`, `entities`, `external_leave_budgets`, `external_leave_types`, `labels`, `leave_types`, `public_holidays`, `sick_leave_dossiers`, `sick_leave_phases`, `teams_information`, `time_off`, `time_tracking`, `users`, `work_location_categories`Diffed against: <https://api.hoorayhr.io/swagger.json>-- [ ] `/external-leave-budgets` — per-user leave balances - the core HR analytical metric next to time-off we already sync (high)+- [x] `/external-leave-budgets` — per-user leave balances - the core HR analytical metric next to time-off we already sync (high)- [ ] `/attendance-report` — prebuilt attendance breakdown joining time tracking and absence (high)-- [ ] `/external-leave-types` — lookup resolving the leave type IDs carried on external leave budgets (medium)-- [ ] `/public-holidays` — holiday calendar lookup needed to interpret time-off and time-tracking days (medium)+- [x] `/external-leave-types` — lookup resolving the leave type IDs carried on external leave budgets (medium)+- [x] `/public-holidays` — holiday calendar lookup needed to interpret time-off and time-tracking days (medium)- [ ] `/working-today` — daily who-is-working snapshot for headcount/availability reporting (low)- [ ] `/time-zones` — static lookup for user time zone codes (low)-Note: Fetched the OpenAPI spec at https://api.hoorayhr.io/swagger.json (linked from https://api.hoorayhr.io/documentation). 15 of the 21 GET-listable resources are already covered.+Note: Fetched the OpenAPI spec at https://api.hoorayhr.io/swagger.json (linked from https://api.hoorayhr.io/documentation). 18 of the 21 GET-listable resources are already covered.## Hubplanner — gapsdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/hoorayhr/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/hoorayhr/canonical_descriptions.pyindex d75070506df1..0f8a38753e4c 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/hoorayhr/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/hoorayhr/canonical_descriptions.py@@ -259,6 +259,48 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"updatedAt": "Last updated date of the item.",},},+ "external_leave_types": {+ "description": "A leave type created by an external (OAuth partner) integration, whose budgets are tracked outside HoorayHR's own leave types.",+ "docs_url": _DOCS_URL,+ "columns": {+ "id": "ID of the external leave type.",+ "name": "Name of the external leave type, unique per company.",+ "color": "Color of the external leave type.",+ "icon": "Icon of the external leave type.",+ "leaveInDays": "Tiny-int indicating if the budgets are defined in days instead of minutes.",+ "clientId": "Client ID of the OAuth client that created the external leave type.",+ "createdAt": "Creation date of the external leave type.",+ "updatedAt": "Last updated date of the external leave type.",+ },+ },+ "external_leave_budgets": {+ "description": "A user's yearly leave budget for an external leave type: transferred, received, expired, spent, and available amounts.",+ "docs_url": _DOCS_URL,+ "columns": {+ "id": "ID of the external leave budget record.",+ "externalLeaveTypeId": "ID of the external leave type.",+ "userId": "Unique id of the user of the external leave budget record.",+ "year": "Year of the external leave budget record.",+ "transferred": "Budget transferred from the previous year (in minutes or days, depending on leaveInDays of the related external leave type).",+ "received": "Budget received this year (in minutes or days, depending on leaveInDays of the related external leave type).",+ "expired": "Budget expired this year (in minutes or days, depending on leaveInDays of the related external leave type).",+ "spent": "Budget spent this year (in minutes or days, depending on leaveInDays of the related external leave type).",+ "available": "Budget available this year (in minutes or days, depending on leaveInDays of the related external leave type).",+ "createdAt": "Creation date of the external leave budget.",+ "updatedAt": "Last updated date of the external leave budget.",+ },+ },+ "public_holidays": {+ "description": "A company public holiday from the previous, current, and next calendar year, with the active users it applies to.",+ "docs_url": _DOCS_URL,+ "columns": {+ "id": "The holiday unique ID.",+ "name": "The name of the holiday, localized to the language of the user the API key belongs to.",+ "date": "The date of the holiday (YYYY-MM-DD).",+ "subtractFromBudget": "Whether the holiday is subtracted from the leave budget.",+ "userIds": "IDs of the active users the holiday applies to, across all holiday policies that include it.",+ },+ },"teams_information": {"description": "A team in the company, with its leaders and members.","docs_url": _DOCS_URL,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/hoorayhr/hoorayhr.py b/products/warehouse_sources/backend/temporal/data_imports/sources/hoorayhr/hoorayhr.pyindex 30d71a065e6c..567f0a4d6c41 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/hoorayhr/hoorayhr.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/hoorayhr/hoorayhr.py@@ -1,16 +1,68 @@+from collections.abc import Callable, Iterable, Iterator+from datetime import date+from typing import Any+from products.warehouse_sources.backend.temporal.data_imports.sources.common.http import make_tracked_sessionfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source import (RESTAPIConfig,rest_api_resource,)+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import ClientConfigfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.source_helpers import validate_via_probefrom products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponsefrom products.warehouse_sources.backend.temporal.data_imports.sources.hoorayhr.settings import (HOORAYHR_BASE_URL,HOORAYHR_ENDPOINTS,+ PUBLIC_HOLIDAYS_YEARS_AHEAD,+ PUBLIC_HOLIDAYS_YEARS_BACK,)+def _client_config(api_key: str) -> ClientConfig:+ return {+ "base_url": HOORAYHR_BASE_URL,+ "headers": {"Accept": "application/json"},+ # Both personal API keys (pk_ prefixed) and partner OAuth access tokens are sent as+ # `Authorization: Bearer <token>`.+ "auth": {"type": "bearer", "token": api_key},+ # No pagination is documented on any list endpoint — each table is a single bare-array+ # page, full refresh only.+ "paginator": "single_page",+ "request_timeout": (10.0, 60.0),+ # Responses carry employee records and leave balances the generic sample scrubbers don't target.+ "capture": False,+ }+++def _public_holiday_pages(api_key: str, team_id: int, job_id: str, today: date) -> Iterator[list[dict[str, Any]]]:+ path = HOORAYHR_ENDPOINTS["public_holidays"].path+ for year in range(today.year - PUBLIC_HOLIDAYS_YEARS_BACK, today.year + PUBLIC_HOLIDAYS_YEARS_AHEAD + 1):+ rest_config: RESTAPIConfig = {+ "client": _client_config(api_key),+ "resource_defaults": None,+ "resources": [+ {+ "name": "public_holidays",+ "endpoint": {+ "path": path,+ "params": {"date[$gte]": f"{year}-01-01", "date[$lte]": f"{year}-12-31"},+ },+ }+ ],+ }+ merged: dict[tuple[Any, Any], dict[str, Any]] = {}+ for page in rest_api_resource(rest_config, team_id, job_id, None):+ for row in page:+ user_ids = row.get("userIds") or []+ existing = merged.get((row["id"], row["date"]))+ if existing is None:+ merged[(row["id"], row["date"])] = {**row, "userIds": list(dict.fromkeys(user_ids))}+ else:+ existing["userIds"] = list(dict.fromkeys([*existing["userIds"], *user_ids]))+ if merged:+ yield list(merged.values())++def hoorayhr_source(api_key: str,endpoint: str,@@ -19,27 +71,22 @@ def hoorayhr_source() -> SourceResponse:config = HOORAYHR_ENDPOINTS[endpoint]- rest_config: RESTAPIConfig = {- "client": {- "base_url": HOORAYHR_BASE_URL,- "headers": {"Accept": "application/json"},- # Both personal API keys (pk_ prefixed) and partner OAuth access tokens are sent as- # `Authorization: Bearer <token>`.- "auth": {"type": "bearer", "token": api_key},- # No pagination is documented on any list endpoint — each table is a single bare-array- # page, full refresh only.- "paginator": "single_page",- },- "resource_defaults": None,- "resources": [{"name": endpoint, "endpoint": {"path": config.path}}],- }-- resource = rest_api_resource(rest_config, team_id, job_id, None)+ items: Callable[[], Iterable[Any]]+ if endpoint == "public_holidays":+ items = lambda: _public_holiday_pages(api_key, team_id, job_id, date.today())+ else:+ rest_config: RESTAPIConfig = {+ "client": _client_config(api_key),+ "resource_defaults": None,+ "resources": [{"name": endpoint, "endpoint": {"path": config.path}}],+ }+ resource = rest_api_resource(rest_config, team_id, job_id, None)+ items = lambda: resourcehas_partition_key = config.partition_key is not Nonereturn SourceResponse(name=endpoint,- items=lambda: resource,+ items=items,primary_keys=config.primary_keys,# Month is the coarsest datetime tier; the auto-repartitioner only steps finer, so this# gives it the most headroom. Endpoints without a stable creation field stay unpartitioned.diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/hoorayhr/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/hoorayhr/settings.pyindex 50b79ef2df8b..a7da8e46de60 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/hoorayhr/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/hoorayhr/settings.py@@ -18,9 +18,9 @@ class HoorayHREndpointConfig:# HoorayHR's public API (OpenAPI spec at https://api.hoorayhr.io/swagger.json) exposes no pagination,# no cursors, and no server-side timestamp filters on any of these list endpoints — each returns the# full collection as one bare JSON array, so every table is full refresh only (matching the Airbyte-# connector's capabilities). Report-style endpoints that require date-range parameters-# (/attendance-report, /working-today, /public-holidays) are point-in-time views, not warehouse-# tables, and are deliberately not synced.+# connector's capabilities). Report-style endpoints (/attendance-report, /working-today) aggregate+# data we already sync over a caller-chosen window and are point-in-time views, not warehouse tables,+# so they are deliberately not synced.HOORAYHR_ENDPOINTS: dict[str, HoorayHREndpointConfig] = {"users": HoorayHREndpointConfig(name="users", path="/users", partition_key="createdAt"),"time_off": HoorayHREndpointConfig(name="time_off", path="/time-off", partition_key="createdAt"),@@ -48,10 +48,25 @@ HOORAYHR_ENDPOINTS: dict[str, HoorayHREndpointConfig] = {"work_location_categories": HoorayHREndpointConfig(name="work_location_categories", path="/work-location-categories", partition_key="createdAt"),+ "external_leave_types": HoorayHREndpointConfig(+ name="external_leave_types", path="/external-leave-types", partition_key="createdAt"+ ),+ "external_leave_budgets": HoorayHREndpointConfig(+ name="external_leave_budgets", path="/external-leave-budgets", partition_key="createdAt"+ ),+ # Requires a date window of at most one year, so it is fetched one calendar year at a time (see+ # PUBLIC_HOLIDAYS_YEARS_*). A holiday in several policies comes back once per policy with no policy+ # id; those records are merged into one row per (id, date).+ "public_holidays": HoorayHREndpointConfig(+ name="public_holidays", path="/public-holidays", primary_keys=["id", "date"]+ ),# Rows are teams (with member/leader user-id arrays), keyed by teamId; no timestamps exposed."teams_information": HoorayHREndpointConfig(name="teams_information", path="/teams-information", primary_keys=["teamId"]),}+PUBLIC_HOLIDAYS_YEARS_BACK = 1+PUBLIC_HOLIDAYS_YEARS_AHEAD = 1+ENDPOINTS = tuple(HOORAYHR_ENDPOINTS.keys())diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/hoorayhr/tests/test_hoorayhr.py b/products/warehouse_sources/backend/temporal/data_imports/sources/hoorayhr/tests/test_hoorayhr.pyindex ce3f63a6ac6f..09f514dd96e4 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/hoorayhr/tests/test_hoorayhr.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/hoorayhr/tests/test_hoorayhr.py@@ -2,6 +2,7 @@ import jsonfrom typing import Anyimport pytest+import time_machinefrom unittest import mockfrom requests import Response@@ -41,7 +42,7 @@ def _wire(session: mock.MagicMock, responses: list[Response]) -> list[dict[str,prepared.headers = {}if request.auth is not None:request.auth(prepared)- seen.append({"url": request.url, "auth_headers": dict(prepared.headers)})+ seen.append({"url": request.url, "params": request.params, "auth_headers": dict(prepared.headers)})return preparedsession.prepare_request.side_effect = _prepare@@ -71,6 +72,42 @@ class TestHoorayHRTransport:assert seen[0]["url"] == f"{HOORAYHR_BASE_URL}/time-off"assert seen[0]["auth_headers"]["Authorization"] == "Bearer pk_test_key"+ @time_machine.travel("2026-06-15T12:00:00Z", tick=False)+ @mock.patch(CLIENT_SESSION_PATCH)+ def test_public_holidays_fetches_each_year_and_merges_policy_duplicates(self, MockSession) -> None:+ session = MockSession.return_value+ seen = _wire(+ session,+ [+ _response([]),+ _response(+ [+ {"id": 7, "name": "New Year", "date": "2026-01-01", "userIds": [1, 2]},+ {"id": 7, "name": "New Year", "date": "2026-01-01", "userIds": [2, 3]},+ {"id": 8, "name": "Kings Day", "date": "2026-04-27", "userIds": [1]},+ ]+ ),+ _response([{"id": 7, "name": "New Year", "date": "2027-01-01", "userIds": [1]}]),+ ],+ )++ batches = _batches(_source("public_holidays"))++ assert batches == [+ [+ {"id": 7, "name": "New Year", "date": "2026-01-01", "userIds": [1, 2, 3]},+ {"id": 8, "name": "Kings Day", "date": "2026-04-27", "userIds": [1]},+ ],+ [{"id": 7, "name": "New Year", "date": "2027-01-01", "userIds": [1]}],+ ]+ assert [s["params"] for s in seen] == [+ {"date[$gte]": "2025-01-01", "date[$lte]": "2025-12-31"},+ {"date[$gte]": "2026-01-01", "date[$lte]": "2026-12-31"},+ {"date[$gte]": "2027-01-01", "date[$lte]": "2027-12-31"},+ ]+ assert all(s["url"] == f"{HOORAYHR_BASE_URL}/public-holidays" for s in seen)+ assert seen[0]["auth_headers"]["Authorization"] == "Bearer pk_test_key"+class TestSourceResponseConfig:def test_all_endpoints_buildable_with_declared_keys(self) -> None: