: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(data-warehouse): add greenhouse stages, openings, roles and custom field tables (#109927)
Tom Owersb17399f5d6b8
diff --git a/posthog/test/repo_invariants/dataclass_frozen_baseline.txt b/posthog/test/repo_invariants/dataclass_frozen_baseline.txtindex 4434498a3788..3ae8ab013373 100644--- a/posthog/test/repo_invariants/dataclass_frozen_baseline.txt+++ b/posthog/test/repo_invariants/dataclass_frozen_baseline.txt@@ -637,7 +637,6 @@1 products/warehouse_sources/backend/temporal/data_imports/sources/granola/granola.py1 products/warehouse_sources/backend/temporal/data_imports/sources/granola/settings.py1 products/warehouse_sources/backend/temporal/data_imports/sources/greenhouse/greenhouse.py-1 products/warehouse_sources/backend/temporal/data_imports/sources/greenhouse/settings.py1 products/warehouse_sources/backend/temporal/data_imports/sources/gridly/gridly.py1 products/warehouse_sources/backend/temporal/data_imports/sources/gridly/settings.py1 products/warehouse_sources/backend/temporal/data_imports/sources/groq/settings.pydiff --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 14afcc76780a..4863a860f5a0 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@@ -3815,14 +3815,14 @@ Note: The public OpenAPI declares only 5 paths: /v1/folders, /v1/notes, /v1/note## Greenhouse — gaps-Today (13): `applications`, `candidates`, `close_reasons`, `departments`, `job_posts`, `jobs`, `offers`, `offices`, `rejection_reasons`, `scheduled_interviews`, `scorecards`, `sources`, `users`+Today (18): `applications`, `candidates`, `close_reasons`, `custom_field_options`, `custom_fields`, `departments`, `job_interview_stages`, `job_posts`, `jobs`, `offers`, `offices`, `openings`, `rejection_reasons`, `scheduled_interviews`, `scorecards`, `sources`, `user_roles`, `users`Diffed against: <https://developers.greenhouse.io/harvest.html>-- [ ] `job_stages (GET /v1/job_stages, /v1/jobs/{id}/stages)` — lookup that resolves the current_stage / stage IDs already carried on synced applications and scorecards (high)-- [ ] `user_roles (GET /v1/user_roles)` — lookup resolving the role on the users table we already sync (high)-- [ ] `job_openings (GET /v1/jobs/{id}/openings)` — per-opening headcount, open/closed dates and close reason - required for time-to-fill and openings-filled reporting (high)-- [ ] `custom_fields + custom_field_options (GET /v1/custom_fields, /v1/custom_fields/{id}/custom_field_options)` — lookup that decodes the custom-field IDs embedded in synced jobs, candidates and applications (high)+- [x] `job_stages (GET /v1/job_stages, /v1/jobs/{id}/stages)` — lookup that resolves the current_stage / stage IDs already carried on synced applications and scorecards (high). Shipped as `job_interview_stages` from `GET /v3/job_interview_stages` (Harvest v3 only).+- [x] `user_roles (GET /v1/user_roles)` — lookup resolving the role on the users table we already sync (high). Shipped as `user_roles` from `GET /v3/user_roles` (Harvest v3 only).+- [x] `job_openings (GET /v1/jobs/{id}/openings)` — per-opening headcount, open/closed dates and close reason - required for time-to-fill and openings-filled reporting (high). Shipped as `openings` from the top-level `GET /v3/openings` (Harvest v3 only).+- [x] `custom_fields + custom_field_options (GET /v1/custom_fields, /v1/custom_fields/{id}/custom_field_options)` — lookup that decodes the custom-field IDs embedded in synced jobs, candidates and applications (high). Shipped as `custom_fields` and `custom_field_options` from `GET /v3/custom_fields` and `GET /v3/custom_field_options` (Harvest v3 only).- [ ] `activity_feed (GET /v1/candidates/{id}/activity_feed)` — candidate-level event/state history - the only source of note and email activity timestamps (medium)- [ ] `demographic_answers (GET /v1/demographic/answers, /v1/applications/{id}/demographic/answers)` — DEI breakdown dimension joined to applications (medium)- [ ] `demographic_questions + question_sets + answer_options (GET /v1/demographic/questions, /question_sets, /answer_options)` — lookup tables that label the demographic answer IDs (medium)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/greenhouse/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/greenhouse/canonical_descriptions.pyindex e4973f443928..b81b4e4b08a1 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/greenhouse/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/greenhouse/canonical_descriptions.py@@ -193,4 +193,64 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"name": "Name of the close reason.",},},+ "job_interview_stages": {+ "description": "A stage on a job's interview plan, such as Application Review, Phone Screen, or Offer.",+ "docs_url": "https://harvestdocs.greenhouse.io/reference/get_v3-job-interview-stages",+ "columns": _columns(+ job_id="ID of the job whose interview plan the stage belongs to.",+ name="Name of the stage on the job's interview plan.",+ sort_order="Position of the stage in the interview plan, ascending from 0.",+ active="Whether the stage is on the job's current interview plan.",+ ),+ },+ "openings": {+ "description": "A single headcount slot on a job. An opening closes when a candidate is hired into it or it is closed without a hire.",+ "docs_url": "https://harvestdocs.greenhouse.io/reference/get_v3-openings",+ "columns": _columns(+ job_id="ID of the job the opening belongs to.",+ opening_id="External identifier for the opening, such as an HRIS position ID.",+ opened_at="Time at which the opening became available to fill.",+ closed_at="Time at which the opening was closed.",+ open="Whether the opening is still available to fill.",+ application_id="ID of the application hired into the opening.",+ close_reason_id="ID of the close reason recorded when the opening was closed.",+ target_start_on="Target start date for the hire that fills the opening.",+ sort_order="Position of the opening in the job's list of openings.",+ custom_fields="Custom field values set on the opening.",+ ),+ },+ "user_roles": {+ "description": "An access role that a Greenhouse user can hold, such as Standard, Private, or Site Admin.",+ "docs_url": "https://harvestdocs.greenhouse.io/reference/get_v3-user-roles",+ "columns": _columns(+ name="Display name of the role.",+ role_type="Category of access the role grants: job_admin or site_admin.",+ ),+ },+ "custom_fields": {+ "description": "An organization-defined custom field on jobs, offers, openings, candidates, applications, or users.",+ "docs_url": "https://harvestdocs.greenhouse.io/reference/get_v3-custom-fields",+ "columns": _columns(+ name="Display name of the custom field.",+ name_key="Stable lowercase key derived from the field name.",+ field_type="Resource the field attaches to, such as job, offer, or candidate.",+ value_type="Data type of the field, such as short_text, single_select, or date.",+ active="Whether the field is in use. False after the field is archived.",+ private="Whether only users with the View Private permission can see the field.",+ required="Whether the UI requires a value before the parent record can be saved.",+ sort_order="Display order of the field within its field type.",+ description="Helper text shown below the field label.",+ ),+ },+ "custom_field_options": {+ "description": "A selectable value on a single_select or multi_select custom field.",+ "docs_url": "https://harvestdocs.greenhouse.io/reference/get_v3-custom-field-options",+ "columns": _columns(+ custom_field_id="ID of the custom field the option belongs to.",+ name="Display label of the option.",+ external_id="External identifier for the option from the source system.",+ sort_order="Display order of the option in the field's dropdown.",+ active="Whether the option can still be selected. False after the option is archived.",+ ),+ },}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/greenhouse/greenhouse.py b/products/warehouse_sources/backend/temporal/data_imports/sources/greenhouse/greenhouse.pyindex ff6165b56d64..3e00dcb94d56 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/greenhouse/greenhouse.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/greenhouse/greenhouse.py@@ -41,6 +41,10 @@ MISSING_V3_CREDENTIALS_ERROR = ("**Harvest V3 (OAuth)** credential, and enter its client ID and client secret.")MISSING_V1_CREDENTIALS_ERROR = "Greenhouse Harvest v1 requires an API key."+V3_ONLY_ENDPOINT_ERROR = (+ "This Greenhouse table needs Harvest v3, but this source uses Harvest v1. "+ "Create a new Greenhouse source with a Harvest V3 (OAuth) credential to sync it."+)def _base_url(api_version: str) -> str:@@ -190,6 +194,8 @@ def greenhouse_source(incremental_field: str | None = None,) -> SourceResponse:config = GREENHOUSE_ENDPOINTS[endpoint]+ if config.v3_only and api_version != GREENHOUSE_V3:+ raise ValueError(V3_ONLY_ENDPOINT_ERROR)params = _build_initial_params(config, api_version, should_use_incremental_field, db_incremental_field_last_value, incremental_fielddiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/greenhouse/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/greenhouse/settings.pyindex 9908995190bf..dbec15949157 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/greenhouse/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/greenhouse/settings.py@@ -8,7 +8,7 @@ GREENHOUSE_V1 = "v1"GREENHOUSE_V3 = "v3"-@dataclass+@dataclass(frozen=True)class GreenhouseEndpointConfig:name: strpath: str@@ -25,6 +25,8 @@ class GreenhouseEndpointConfig:incremental_filter_params: dict[str, str] = field(default_factory=dict)# Harvest v3 path, where v3 renamed the collection. ``None`` means v3 kept the v1 name.v3_path: Optional[str] = None+ # Harvest v1 has no top-level list for the resource, or lacks the timestamps it is keyed on.+ v3_only: bool = Falsedef path_for_version(self, api_version: str) -> str:if api_version == GREENHOUSE_V3 and self.v3_path is not None:@@ -48,6 +50,8 @@ def _datetime_incremental_field(name: str) -> IncrementalField:# reference endpoints (departments, offices, sources, rejection/close reasons) have no# timestamp filter and ship full refresh. Per-parent fan-out streams (activity feeds,# per-application interviews/scorecards) are intentionally deferred to a later pass.+# The v3-only lookups (stages, openings, roles, custom fields) filter on `updated_at` /+# `created_at` server-side and ship incremental.GREENHOUSE_ENDPOINTS: dict[str, GreenhouseEndpointConfig] = {"candidates": GreenhouseEndpointConfig(name="candidates",@@ -191,10 +195,72 @@ GREENHOUSE_ENDPOINTS: dict[str, GreenhouseEndpointConfig] = {path="/close_reasons",primary_keys=["id"],),+ "job_interview_stages": GreenhouseEndpointConfig(+ name="job_interview_stages",+ path="/job_interview_stages",+ v3_only=True,+ primary_keys=["id"],+ partition_key="created_at",+ incremental_fields=[+ _datetime_incremental_field("updated_at"),+ _datetime_incremental_field("created_at"),+ ],+ ),+ "openings": GreenhouseEndpointConfig(+ name="openings",+ path="/openings",+ v3_only=True,+ primary_keys=["id"],+ partition_key="created_at",+ incremental_fields=[+ _datetime_incremental_field("updated_at"),+ _datetime_incremental_field("created_at"),+ ],+ ),+ "user_roles": GreenhouseEndpointConfig(+ name="user_roles",+ path="/user_roles",+ v3_only=True,+ primary_keys=["id"],+ partition_key="created_at",+ incremental_fields=[+ _datetime_incremental_field("updated_at"),+ _datetime_incremental_field("created_at"),+ ],+ ),+ "custom_fields": GreenhouseEndpointConfig(+ name="custom_fields",+ path="/custom_fields",+ v3_only=True,+ primary_keys=["id"],+ partition_key="created_at",+ incremental_fields=[+ _datetime_incremental_field("updated_at"),+ _datetime_incremental_field("created_at"),+ ],+ ),+ "custom_field_options": GreenhouseEndpointConfig(+ name="custom_field_options",+ path="/custom_field_options",+ v3_only=True,+ primary_keys=["id"],+ partition_key="created_at",+ incremental_fields=[+ _datetime_incremental_field("updated_at"),+ _datetime_incremental_field("created_at"),+ ],+ ),}ENDPOINTS = tuple(GREENHOUSE_ENDPOINTS.keys())++def endpoints_for_version(api_version: str) -> tuple[str, ...]:+ if api_version == GREENHOUSE_V3:+ return ENDPOINTS+ return tuple(name for name, config in GREENHOUSE_ENDPOINTS.items() if not config.v3_only)++INCREMENTAL_FIELDS: dict[str, list[IncrementalField]] = {name: config.incremental_fields for name, config in GREENHOUSE_ENDPOINTS.items()}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/greenhouse/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/greenhouse/source.pyindex bf434d7102ae..0bae70a805e8 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/greenhouse/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/greenhouse/source.py@@ -31,16 +31,17 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.generated_)from products.warehouse_sources.backend.temporal.data_imports.sources.greenhouse.greenhouse import (MISSING_V3_CREDENTIALS_ERROR,+ V3_ONLY_ENDPOINT_ERROR,GreenhouseResumeConfig,greenhouse_source,validate_credentials as validate_greenhouse_credentials,)from products.warehouse_sources.backend.temporal.data_imports.sources.greenhouse.settings import (- ENDPOINTS,GREENHOUSE_ENDPOINTS,GREENHOUSE_V1,GREENHOUSE_V3,INCREMENTAL_FIELDS,+ endpoints_for_version,)from products.warehouse_sources.backend.types import ExternalDataSourceType@@ -125,7 +126,9 @@ The API key field is only for connections still on Harvest v1, which Greenhouseforce_refresh: bool = False,api_version: str | None = None,) -> list[SourceSchema]:- return build_endpoint_schemas(ENDPOINTS, INCREMENTAL_FIELDS, names)+ return build_endpoint_schemas(+ endpoints_for_version(self.resolve_api_version(api_version)), INCREMENTAL_FIELDS, names+ )def validate_credentials(self,@@ -142,6 +145,8 @@ The API key field is only for connections still on Harvest v1, which Greenhouse# be scoped only to the endpoints the user wants. For a per-schema check, probe that# endpoint and surface a missing-scope error.if schema_name is not None and schema_name in GREENHOUSE_ENDPOINTS:+ if schema_name not in endpoints_for_version(version):+ return False, V3_ONLY_ENDPOINT_ERRORreturn validate_greenhouse_credentials(version,api_key=config.api_key,@@ -165,6 +170,7 @@ The API key field is only for connections still on Harvest v1, which Greenhouse"403 Client Error: Forbidden for url: https://harvest.greenhouse.io": "Your Greenhouse credentials do not have the required permissions. Please grant read access to this resource and try again. Harvest v3 list endpoints also require the authorizing user to be a site admin.",OAUTH2_PERMANENT_ERROR_MARKER: "Greenhouse authentication failed. Please check the client ID and client secret of your Harvest V3 (OAuth) credential.",MISSING_V3_CREDENTIALS_ERROR: None,+ V3_ONLY_ENDPOINT_ERROR: None,}def get_resumable_source_manager(self, inputs: SourceInputs) -> ResumableSourceManager[GreenhouseResumeConfig]:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/greenhouse/tests/test_greenhouse.py b/products/warehouse_sources/backend/temporal/data_imports/sources/greenhouse/tests/test_greenhouse.pyindex 905020d7b21d..d0acdff36c79 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/greenhouse/tests/test_greenhouse.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/greenhouse/tests/test_greenhouse.py@@ -1,3 +1,4 @@+import reimport jsonimport dataclassesfrom datetime import UTC, date, datetime@@ -17,6 +18,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.greenhouseGREENHOUSE_ENDPOINTS,GREENHOUSE_TOKEN_URL,PAGE_SIZE,+ V3_ONLY_ENDPOINT_ERROR,GreenhouseResumeConfig,_build_auth,_build_initial_params,@@ -60,10 +62,13 @@ def _make_manager(resume_state: GreenhouseResumeConfig | None = None) -> MagicModef _source(endpoint: str, **kwargs: Any) -> Any:# Transport tests run on v1: its HTTP Basic auth needs no token exchange, so the only network# boundary is the patched rest_client session. Version-specific request shape is covered by the- # param/auth/url tests below.+ # param/auth/url tests below. v3-only endpoints build on v3; the token is minted lazily on the+ # first request, so building the response needs no network.kwargs.setdefault("resumable_source_manager", _make_manager())- kwargs.setdefault("api_version", GREENHOUSE_V1)- return greenhouse_source(endpoint, team_id=1, job_id="j", api_key="key", **kwargs)+ kwargs.setdefault("api_version", GREENHOUSE_V3 if GREENHOUSE_ENDPOINTS[endpoint].v3_only else GREENHOUSE_V1)+ return greenhouse_source(+ endpoint, team_id=1, job_id="j", api_key="key", client_id="cid", client_secret="csecret", **kwargs+ )class TestFormatDatetime:@@ -252,6 +257,11 @@ class TestGreenhouseSourceResponse:def test_partition_key_is_never_updated_at(self, endpoint: str) -> None:assert GREENHOUSE_ENDPOINTS[endpoint].partition_key not in ("updated_at", "last_activity_at")+ @pytest.mark.parametrize("endpoint", [name for name, config in GREENHOUSE_ENDPOINTS.items() if config.v3_only])+ def test_v3_only_endpoint_refuses_to_sync_on_v1(self, endpoint: str) -> None:+ with pytest.raises(ValueError, match=re.escape(V3_ONLY_ENDPOINT_ERROR)):+ _source(endpoint, api_version=GREENHOUSE_V1)+def test_sort_mode_is_ascending(self) -> None:response = _source("candidates")assert response.sort_mode == "asc"@@ -266,6 +276,7 @@ class TestRequestUrlPerVersion:# v3 renamed this collection; the schema (and warehouse table) keeps the v1 name.("scheduled_interviews", GREENHOUSE_V1, "https://harvest.greenhouse.io/v1/scheduled_interviews"),("scheduled_interviews", GREENHOUSE_V3, "https://harvest.greenhouse.io/v3/interviews"),+ ("job_interview_stages", GREENHOUSE_V3, "https://harvest.greenhouse.io/v3/job_interview_stages"),],)@mock.patch(f"{OAUTH_MODULE}.OAuth2Auth._obtain_token")diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/greenhouse/tests/test_greenhouse_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/greenhouse/tests/test_greenhouse_source.pyindex 1423178f944a..a6a46c9acbe6 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/greenhouse/tests/test_greenhouse_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/greenhouse/tests/test_greenhouse_source.py@@ -126,6 +126,27 @@ class TestGreenhouseSource:assert mock_validate.call_args.args[0] == expected_versionassert mock_validate.call_args.kwargs["path"] == expected_path+ @pytest.mark.parametrize("pinned_version, lists_v3_only", [(None, True), ("v3", True), ("v1", False)])+ def test_get_schemas_lists_v3_only_tables_only_on_v3(self, pinned_version: str | None, lists_v3_only: bool) -> None:+ names = {+ schema.name for schema in self.source.get_schemas(self.config, self.team_id, api_version=pinned_version)+ }++ assert "candidates" in names+ assert ("openings" in names) is lists_v3_only++ @mock.patch(+ "products.warehouse_sources.backend.temporal.data_imports.sources.greenhouse.source.validate_greenhouse_credentials"+ )+ def test_validate_credentials_rejects_v3_only_schema_on_v1(self, mock_validate: mock.MagicMock) -> None:+ is_valid, error = self.source.validate_credentials(+ self.config, self.team_id, schema_name="openings", api_version="v1"+ )++ assert is_valid is False+ assert error is not None and "Harvest v3" in error+ mock_validate.assert_not_called()+@pytest.mark.parametrize("pinned_version, expected_version", [(None, "v3"), ("v3", "v3"), ("v1", "v1")])@mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.greenhouse.source.greenhouse_source")def test_source_for_pipeline_passes_the_resolved_version(