: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(configcat): sync configs, environments, settings and flag values (#103455)
Tom Owers676a2e04bc9d
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 b6685821050e..929a42f19617 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@@ -1942,16 +1942,16 @@ Diffed against: <https://api.doc.concordnow.com/concord-openapi-bundled.yaml>Note: Bundled OpenAPI 3.1 spec (redoc spec-url from api.doc.concordnow.com). Top-level collections are well covered; every gap is a per-agreement sub-resource, so implementing them means fanning out over the agreements table.-## ConfigCat — **thin**+## ConfigCat — gaps-Today (2): `organizations`, `products`+Today (6): `configs`, `environments`, `organizations`, `products`, `setting_values`, `settings`Diffed against: <https://api.configcat.com/docs/v1/swagger.json>-- [ ] `GET /v1/products/{productId}/configs` — config lookup table; every setting and value row is keyed by configId (high)-- [ ] `GET /v1/products/{productId}/environments` — environment lookup table; flag values are per environment (high)-- [ ] `GET /v1/configs/{configId}/settings` — the feature flag / setting catalog - the product's headline object (high)-- [ ] `GET /v2/configs/{configId}/environments/{environmentId}/values` — flag values and targeting rules per environment; what is actually rolled out where (high)+- [x] `GET /v1/products/{productId}/configs` — config lookup table; every setting and value row is keyed by configId (high)+- [x] `GET /v1/products/{productId}/environments` — environment lookup table; flag values are per environment (high)+- [x] `GET /v1/configs/{configId}/settings` — the feature flag / setting catalog - the product's headline object (high)+- [x] `GET /v2/configs/{configId}/environments/{environmentId}/values` — flag values and targeting rules per environment; what is actually rolled out where (high)- [ ] `GET /v2/products/{productId}/auditlogs and /v2/organizations/{organizationId}/auditlogs` — change history - who flipped which flag when (high)- [ ] `GET /v1/products/{productId}/segments` — reusable targeting segments referenced by flag rules (medium)- [ ] `GET /v1/products/{productId}/tags (and /v1/tags/{tagId}/settings)` — tag lookup plus the tag->setting junction (medium)@@ -1961,7 +1961,7 @@ Diffed against: <https://api.configcat.com/docs/v1/swagger.json>- [ ] `GET /v1/settings/{settingId}/code-references` — where each flag is referenced in source, for removal analysis (low)- [ ] `GET /v1/configs/{configId}/deleted-settings` — deleted flags, needed to keep historical joins from dangling (low)-Note: Source exposes 2 static endpoints (settings.py CONFIGCAT_ENDPOINTS = products, organizations) with no dynamic discovery - confirmed in products/warehouse_sources/backend/temporal/data_imports/sources/configcat/source.py. The vendor spec has ~48 GET operations. The entire config/environment/setting model - i.e. what ConfigCat actually is - is unsynced. Note: I include feature-flag 'settings' despite the generic exclusion on feature flags, because here they are the vendor's core catalog object, not incidental plumbing.+Note: Source exposes 6 static endpoints (settings.py CONFIGCAT_ENDPOINTS) with no dynamic discovery. The vendor spec has ~48 GET operations. The config/environment/setting model - i.e. what ConfigCat actually is - now syncs; the remaining gaps are audit logs, segments, tags, members and the cleanup reports. Note: I include feature-flag 'settings' despite the generic exclusion on feature flags, because here they are the vendor's core catalog object, not incidental plumbing.## Confluence — gapsdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/configcat/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/configcat/canonical_descriptions.pyindex 7d4a282ff7ff..5728fbd47d3c 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/configcat/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/configcat/canonical_descriptions.py@@ -26,4 +26,70 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"name": "The name of the organization.",},},+ "configs": {+ "description": "A ConfigCat config — the container within a product that groups feature flags and settings.",+ "docs_url": "https://api.configcat.com/docs",+ "columns": {+ "configId": "The unique identifier (GUID) of the config.",+ "name": "The name of the config.",+ "description": "The description of the config.",+ "order": "The display order of the config within the product.",+ "migratedConfigId": "The identifier of the config this one was migrated from, when it replaced an older config.",+ "evaluationVersion": "The flag evaluation version the config uses (v1 or v2).",+ "product": "The product that owns the config (nested object with productId and name).",+ },+ },+ "environments": {+ "description": "A ConfigCat environment — a deployment target such as production or staging, which each feature flag holds its own value in.",+ "docs_url": "https://api.configcat.com/docs",+ "columns": {+ "environmentId": "The unique identifier (GUID) of the environment.",+ "name": "The name of the environment.",+ "color": "The color configured for the environment on the ConfigCat dashboard.",+ "description": "The description of the environment.",+ "order": "The display order of the environment within the product.",+ "reasonRequired": "Whether a mandatory reason is required every time a flag is saved in this environment.",+ "approveRequired": "Whether changes must be approved before they apply in this environment.",+ "product": "The product that owns the environment (nested object with productId and name).",+ },+ },+ "settings": {+ "description": "A ConfigCat feature flag or setting — the definition of the flag itself, without its per-environment values.",+ "docs_url": "https://api.configcat.com/docs",+ "columns": {+ "settingId": "The identifier of the feature flag or setting.",+ "key": "The key the SDKs read the feature flag or setting by.",+ "name": "The name of the feature flag or setting.",+ "hint": "The description of the feature flag or setting.",+ "order": "The display order of the feature flag or setting within the config.",+ "settingType": "The value type of the feature flag or setting (boolean, string, int or double).",+ "isJson": "Whether string values are validated as JSON.",+ "configId": "The unique identifier (GUID) of the config the feature flag or setting belongs to.",+ "configName": "The name of the config the feature flag or setting belongs to.",+ "createdAt": "The creation time of the feature flag or setting.",+ "tags": "The tags attached to the feature flag or setting.",+ "predefinedVariations": "The predefined variations of the feature flag or setting.",+ },+ },+ "setting_values": {+ "description": "The value a ConfigCat feature flag or setting evaluates to in one environment, with its targeting rules — one row per flag per environment.",+ "docs_url": "https://api.configcat.com/docs",+ "columns": {+ "configId": "The unique identifier (GUID) of the config the value belongs to.",+ "environmentId": "The unique identifier (GUID) of the environment the value applies to.",+ "settingId": "The identifier of the feature flag or setting the value belongs to.",+ "defaultValue": "The value served when no targeting rule matches.",+ "targetingRules": "The targeting rules of the feature flag or setting in this environment.",+ "setting": "The feature flag or setting the value belongs to (nested object with settingId, key, name and type).",+ "percentageEvaluationAttribute": "The user attribute used for percentage evaluation. Defaults to the Identifier attribute.",+ "updatedAt": "The time the feature flag or setting was last updated in this environment.",+ "lastVersionId": "The version identifier of the last change made in this environment.",+ "lastUpdaterUserEmail": "The email of the user who last updated the feature flag or setting.",+ "lastUpdaterUserFullName": "The name of the user who last updated the feature flag or setting.",+ "integrationLinks": "The integration links attached to the feature flag or setting.",+ "settingTags": "The tags attached to the feature flag or setting.",+ "settingIdsWherePrerequisite": "The feature flags and settings that depend on this one as a prerequisite.",+ "changeRequestCount": "The number of open change requests for the feature flag or setting.",+ },+ },}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/configcat/configcat.py b/products/warehouse_sources/backend/temporal/data_imports/sources/configcat/configcat.pyindex b031049c0b39..1b54c6d60ca0 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/configcat/configcat.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/configcat/configcat.py@@ -1,5 +1,8 @@import base64-from typing import Optional+from collections.abc import Iterator+from typing import Any, Optional++import requestsfrom 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 (@@ -10,12 +13,19 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.resSinglePagePaginator,)from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponse-from products.warehouse_sources.backend.temporal.data_imports.sources.configcat.settings import CONFIGCAT_ENDPOINTS+from products.warehouse_sources.backend.temporal.data_imports.sources.configcat.settings import (+ CONFIGCAT_ENDPOINTS,+ ConfigCatEndpointConfig,+)CONFIGCAT_BASE_URL = "https://api.configcat.com"# Cheap org-level list used to confirm the Public API credential is genuine. The credential is# account-wide, so one probe validates access to every list endpoint.DEFAULT_PROBE_PATH = "/v1/organizations"+REQUEST_TIMEOUT_SECONDS = 60+# The v2 values response is an envelope describing one config/environment pair; the per-flag rows+# sit under this key.+SETTING_FORMULAS_SELECTOR = "settingFormulas"def _headers(username: str, password: str) -> dict[str, str]:@@ -25,6 +35,157 @@ def _headers(username: str, password: str) -> dict[str, str]:return {"Authorization": f"Basic {token}", "Accept": "application/json"}+def _get(session: requests.Session, path: str) -> Any:+ response = session.get(f"{CONFIGCAT_BASE_URL}{path}", timeout=REQUEST_TIMEOUT_SECONDS)+ response.raise_for_status()+ return response.json()+++def _get_list(session: requests.Session, path: str) -> list[dict[str, Any]]:+ body = _get(session, path)+ if not isinstance(body, list):+ raise ValueError(f"ConfigCat returned a non-list response body for {path}")+ if any(not isinstance(row, dict) for row in body):+ raise ValueError(f"ConfigCat returned a non-object row for {path}")+ return body+++def _identifier(row: dict[str, Any], field: str) -> str:+ value = row.get(field)+ if isinstance(value, bool) or not isinstance(value, (str, int)) or not str(value):+ raise ValueError(f"ConfigCat row has an invalid {field}")+ return str(value)+++def _ids(rows: list[dict[str, Any]], field: str) -> list[str]:+ return [_identifier(row, field) for row in rows]+++def _product_ids(session: requests.Session) -> list[str]:+ return _ids(_get_list(session, CONFIGCAT_ENDPOINTS["products"].path), "productId")+++def _configs(session: requests.Session, product_id: str) -> list[dict[str, Any]]:+ path = CONFIGCAT_ENDPOINTS["configs"].path.format(productId=product_id)+ rows = _get_list(session, path)+ _ids(rows, "configId")+ return rows+++def _environment_ids(session: requests.Session, product_id: str) -> list[str]:+ path = CONFIGCAT_ENDPOINTS["environments"].path.format(productId=product_id)+ return _ids(_get_list(session, path), "environmentId")+++def _setting_value_rows(body: Any, config_id: str, environment_id: str) -> list[dict[str, Any]]:+ if not isinstance(body, dict):+ raise ValueError(f"ConfigCat returned a non-object values body for config {config_id}")+ formulas = body.get(SETTING_FORMULAS_SELECTOR)+ if not isinstance(formulas, list):+ raise ValueError(f"ConfigCat returned invalid settingFormulas for config {config_id}")++ rows: list[dict[str, Any]] = []+ for formula in formulas:+ if not isinstance(formula, dict):+ raise ValueError(f"ConfigCat returned a non-object setting formula for config {config_id}")+ setting = formula.get("setting")+ if not isinstance(setting, dict):+ raise ValueError(f"ConfigCat returned an invalid setting for config {config_id}")+ _identifier(setting, "settingId")+ rows.append(+ {+ **formula,+ "configId": config_id,+ "environmentId": environment_id,+ "settingId": setting["settingId"],+ }+ )+ return rows+++def _v1_setting_value_rows(body: Any, config_id: str, environment_id: str) -> list[dict[str, Any]]:+ if not isinstance(body, dict):+ raise ValueError(f"ConfigCat returned a non-object values body for config {config_id}")+ values = body.get("settingValues")+ if not isinstance(values, list):+ raise ValueError(f"ConfigCat returned invalid settingValues for config {config_id}")++ rows: list[dict[str, Any]] = []+ for value in values:+ if not isinstance(value, dict):+ raise ValueError(f"ConfigCat returned a non-object setting value for config {config_id}")+ setting = value.get("setting")+ if not isinstance(setting, dict):+ raise ValueError(f"ConfigCat returned an invalid setting for config {config_id}")+ _identifier(setting, "settingId")+ rows.append(+ {+ **value,+ "configId": config_id,+ "environmentId": environment_id,+ "settingId": setting["settingId"],+ }+ )+ return rows+++def _validate_primary_keys(rows: list[dict[str, Any]], primary_keys: list[str]) -> None:+ for row in rows:+ for field in primary_keys:+ _identifier(row, field)+++def _fan_out_rows(session: requests.Session, config: ConfigCatEndpointConfig) -> Iterator[list[dict[str, Any]]]:+ for product_id in _product_ids(session):+ if config.parent == "product":+ rows = _get_list(session, config.path.format(productId=product_id))+ _validate_primary_keys(rows, config.primary_keys)+ if rows:+ yield rows+ continue++ configs = _configs(session, product_id)++ if config.parent == "config":+ for config_row in configs:+ config_id = _identifier(config_row, "configId")+ rows = _get_list(session, config.path.format(configId=config_id))+ _validate_primary_keys(rows, config.primary_keys)+ if rows:+ yield rows+ continue++ environment_ids = _environment_ids(session, product_id)+ for config_row in configs:+ config_id = _identifier(config_row, "configId")+ evaluation_version = config_row.get("evaluationVersion")+ if evaluation_version not in ("v1", "v2"):+ raise ValueError(f"ConfigCat config {config_id} has an invalid evaluationVersion")+ for environment_id in environment_ids:+ if evaluation_version == "v1":+ path = f"/v1/configs/{config_id}/environments/{environment_id}/values"+ rows = _v1_setting_value_rows(_get(session, path), config_id, environment_id)+ else:+ path = config.path.format(configId=config_id, environmentId=environment_id)+ rows = _setting_value_rows(_get(session, path), config_id, environment_id)+ if rows:+ yield rows+++def _fan_out_source(username: str, password: str, config: ConfigCatEndpointConfig) -> SourceResponse:+ def items() -> Iterator[list[dict[str, Any]]]:+ session = make_tracked_session(headers=_headers(username, password), redact_values=(username, password))+ yield from _fan_out_rows(session, config)++ return SourceResponse(+ name=config.name,+ items=items,+ primary_keys=config.primary_keys,+ partition_count=1,+ partition_size=1,+ )++def configcat_source(username: str,password: str,@@ -34,6 +195,9 @@ def configcat_source() -> SourceResponse:config = CONFIGCAT_ENDPOINTS[endpoint]+ if config.parent is not None:+ return _fan_out_source(username, password, config)+rest_config: RESTAPIConfig = {"client": {"base_url": CONFIGCAT_BASE_URL,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/configcat/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/configcat/settings.pyindex 151b0e8e81cc..84baba7ab471 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/configcat/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/configcat/settings.py@@ -1,9 +1,16 @@-from dataclasses import dataclass+from typing import Literal++from posthog.dataclasses import frozenfrom products.warehouse_sources.backend.types import IncrementalField+# Which parent a fan-out endpoint is queried once per. Everything below a product is addressed by+# GUID only, so the deeper resources are reached by walking products first. `config_environment`+# is the config/environment pair the v2 values endpoint takes.+ConfigCatParent = Literal["product", "config", "config_environment"]+-@dataclass+@frozenclass ConfigCatEndpointConfig:name: strpath: str@@ -11,17 +18,44 @@ class ConfigCatEndpointConfig:# differs per resource (products use `productId`, organizations use `organizationId`), so the# primary key is declared per endpoint rather than defaulted.primary_keys: list[str]+ # None for a top-level listing fetched in a single request.+ parent: ConfigCatParent | None = None-# ConfigCat Public Management API top-level list endpoints. Both return a full collection in a-# single response — the API documents no pagination — so sync is full refresh only. The deeper-# resources (configs, environments, settings, values) are hierarchical fan-outs that require a-# parent product id, so they are intentionally excluded from v1.+# ConfigCat Public Management API endpoints. None of them accept a page, cursor or timestamp+# parameter — every response is the full collection — so sync is full refresh only.CONFIGCAT_ENDPOINTS: dict[str, ConfigCatEndpointConfig] = {"products": ConfigCatEndpointConfig(name="products", path="/v1/products", primary_keys=["productId"]),"organizations": ConfigCatEndpointConfig(name="organizations", path="/v1/organizations", primary_keys=["organizationId"]),+ "configs": ConfigCatEndpointConfig(+ name="configs",+ path="/v1/products/{productId}/configs",+ primary_keys=["configId"],+ parent="product",+ ),+ "environments": ConfigCatEndpointConfig(+ name="environments",+ path="/v1/products/{productId}/environments",+ primary_keys=["environmentId"],+ parent="product",+ ),+ # The feature flag catalog. `settingId` is an integer the docs only describe as identifying a+ # flag within its config, so the config is part of the key; rows carry `configId` themselves.+ "settings": ConfigCatEndpointConfig(+ name="settings",+ path="/v1/configs/{configId}/settings",+ primary_keys=["configId", "settingId"],+ parent="config",+ ),+ # What each flag currently evaluates to in each environment, with its targeting rules.+ "setting_values": ConfigCatEndpointConfig(+ name="setting_values",+ path="/v2/configs/{configId}/environments/{environmentId}/values",+ primary_keys=["configId", "environmentId", "settingId"],+ parent="config_environment",+ ),}ENDPOINTS = tuple(CONFIGCAT_ENDPOINTS.keys())diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/configcat/tests/test_configcat.py b/products/warehouse_sources/backend/temporal/data_imports/sources/configcat/tests/test_configcat.pyindex 45b03eaf2666..a6ba925f43a7 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/configcat/tests/test_configcat.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/configcat/tests/test_configcat.py@@ -100,6 +100,162 @@ class TestConfigCatSource:assert urls[0] == f"{CONFIGCAT_BASE_URL}/v1/organizations"+class _FakeSession:+ """Serves canned bodies by path and records every path the fan-out requested."""++ def __init__(self, bodies: dict[str, Any]) -> None:+ self.bodies = bodies+ self.paths: list[str] = []++ def get(self, url: str, timeout: int | None = None) -> Any:+ path = url.removeprefix(CONFIGCAT_BASE_URL)+ self.paths.append(path)+ response = MagicMock()+ response.raise_for_status.return_value = None+ response.json.return_value = self.bodies[path]+ return response+++class TestConfigCatFanOut:+ @staticmethod+ def _run(+ mock_make_session: MagicMock, bodies: dict[str, Any], endpoint: str+ ) -> tuple[list[dict[str, Any]], list[str]]:+ session = _FakeSession(bodies)+ mock_make_session.return_value = session+ rows = _rows(configcat_source("user", "pass", endpoint, team_id=1, job_id="j"))+ return rows, session.paths++ @parameterized.expand(+ [+ ("configs", "/v1/products/{}/configs", "configId"),+ ("environments", "/v1/products/{}/environments", "environmentId"),+ ]+ )+ @mock.patch.object(configcat, "make_tracked_session")+ def test_product_children_are_fetched_once_per_product(+ self, endpoint: str, child_path: str, id_field: str, mock_make_session: MagicMock+ ) -> None:+ bodies = {+ "/v1/products": [{"productId": "p1"}, {"productId": "p2"}],+ child_path.format("p1"): [{id_field: "a"}],+ child_path.format("p2"): [{id_field: "b"}],+ }+ rows, paths = self._run(mock_make_session, bodies, endpoint)++ assert rows == [{id_field: "a"}, {id_field: "b"}]+ assert paths == ["/v1/products", child_path.format("p1"), child_path.format("p2")]++ @mock.patch.object(configcat, "make_tracked_session")+ def test_settings_walk_products_then_configs(self, mock_make_session: MagicMock) -> None:+ bodies = {+ "/v1/products": [{"productId": "p1"}],+ "/v1/products/p1/configs": [{"configId": "c1"}, {"configId": "c2"}],+ "/v1/configs/c1/settings": [{"settingId": 1, "configId": "c1"}],+ "/v1/configs/c2/settings": [{"settingId": 1, "configId": "c2"}],+ }+ rows, paths = self._run(mock_make_session, bodies, "settings")++ # `settingId` repeats across configs, which is why the key is composite.+ assert rows == [{"settingId": 1, "configId": "c1"}, {"settingId": 1, "configId": "c2"}]+ assert paths[-2:] == ["/v1/configs/c1/settings", "/v1/configs/c2/settings"]++ @mock.patch.object(configcat, "make_tracked_session")+ def test_setting_values_pair_configs_with_environments_of_the_same_product(+ self, mock_make_session: MagicMock+ ) -> None:+ bodies = {+ "/v1/products": [{"productId": "p1"}, {"productId": "p2"}],+ "/v1/products/p1/configs": [{"configId": "c1", "evaluationVersion": "v2"}],+ "/v1/products/p1/environments": [{"environmentId": "e1"}],+ "/v1/products/p2/configs": [{"configId": "c2", "evaluationVersion": "v2"}],+ "/v1/products/p2/environments": [{"environmentId": "e2"}],+ "/v2/configs/c1/environments/e1/values": {+ "settingFormulas": [{"setting": {"settingId": 7}, "defaultValue": {"boolValue": True}}]+ },+ "/v2/configs/c2/environments/e2/values": {+ "settingFormulas": [{"setting": {"settingId": 7}, "defaultValue": {"boolValue": False}}]+ },+ }+ rows, paths = self._run(mock_make_session, bodies, "setting_values")++ # A config only has values in its own product's environments — c1/e2 is not a valid pair.+ assert [path for path in paths if path.startswith("/v2/")] == [+ "/v2/configs/c1/environments/e1/values",+ "/v2/configs/c2/environments/e2/values",+ ]+ # The envelope carries the config and environment, so they're lifted onto each row to+ # complete the primary key.+ assert [(row["configId"], row["environmentId"], row["settingId"]) for row in rows] == [+ ("c1", "e1", 7),+ ("c2", "e2", 7),+ ]+ assert rows[0]["defaultValue"] == {"boolValue": True}++ @mock.patch.object(configcat, "make_tracked_session")+ def test_setting_values_non_object_body_fails_loud(self, mock_make_session: MagicMock) -> None:+ bodies = {+ "/v1/products": [{"productId": "p1"}],+ "/v1/products/p1/configs": [{"configId": "c1", "evaluationVersion": "v2"}],+ "/v1/products/p1/environments": [{"environmentId": "e1"}],+ "/v2/configs/c1/environments/e1/values": [],+ }+ with pytest.raises(ValueError, match="non-object values body"):+ self._run(mock_make_session, bodies, "setting_values")++ @mock.patch.object(configcat, "make_tracked_session")+ def test_v1_setting_values_use_v1_endpoint(self, mock_make_session: MagicMock) -> None:+ bodies = {+ "/v1/products": [{"productId": "p1"}],+ "/v1/products/p1/configs": [{"configId": "c1", "evaluationVersion": "v1"}],+ "/v1/products/p1/environments": [{"environmentId": "e1"}],+ "/v1/configs/c1/environments/e1/values": {"settingValues": [{"setting": {"settingId": 7}, "value": True}]},+ }++ rows, paths = self._run(mock_make_session, bodies, "setting_values")++ assert paths[-1] == "/v1/configs/c1/environments/e1/values"+ assert rows == [+ {+ "setting": {"settingId": 7},+ "settingId": 7,+ "value": True,+ "configId": "c1",+ "environmentId": "e1",+ }+ ]++ @parameterized.expand(+ [+ ("non_object_row", [{"productId": "p1"}, "bad"], "non-object row"),+ ("missing_id", [{"name": "missing id"}], "invalid productId"),+ ]+ )+ @mock.patch.object(configcat, "make_tracked_session")+ def test_malformed_fan_out_parent_fails_loud(+ self, _name: str, products: Any, error: str, mock_make_session: MagicMock+ ) -> None:+ with pytest.raises(ValueError, match=error):+ self._run(mock_make_session, {"/v1/products": products}, "configs")++ @mock.patch.object(configcat, "make_tracked_session")+ def test_malformed_setting_formula_fails_loud(self, mock_make_session: MagicMock) -> None:+ bodies = {+ "/v1/products": [{"productId": "p1"}],+ "/v1/products/p1/configs": [{"configId": "c1", "evaluationVersion": "v2"}],+ "/v1/products/p1/environments": [{"environmentId": "e1"}],+ "/v2/configs/c1/environments/e1/values": {"settingFormulas": [{"setting": {}}]},+ }++ with pytest.raises(ValueError, match="invalid settingId"):+ self._run(mock_make_session, bodies, "setting_values")++ @mock.patch.object(configcat, "make_tracked_session")+ def test_fan_out_list_endpoint_non_list_body_fails_loud(self, mock_make_session: MagicMock) -> None:+ with pytest.raises(ValueError, match="list response body"):+ self._run(mock_make_session, {"/v1/products": {"error": "nope"}}, "configs")++class TestCheckAccess:@staticmethoddef _session_for(response: Any) -> MagicMock:@@ -178,3 +334,12 @@ class TestConfigCatSourceResponse:assert CONFIGCAT_ENDPOINTS["products"].primary_keys == ["productId"]assert CONFIGCAT_ENDPOINTS["organizations"].primary_keys == ["organizationId"]assert set(CONFIGCAT_ENDPOINTS) == set(ENDPOINTS)++ @parameterized.expand([(name,) for name, config in CONFIGCAT_ENDPOINTS.items() if config.parent is not None])+ def test_fan_out_keys_include_every_parent_in_the_path(self, endpoint: str) -> None:+ # A fan-out table aggregates rows from every parent, so a key missing a parent id seeds+ # duplicates that every later merge multi-matches.+ config = CONFIGCAT_ENDPOINTS[endpoint]+ for placeholder in ("configId", "environmentId"):+ if f"{{{placeholder}}}" in config.path:+ assert placeholder in config.primary_keys