Skip to content

: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.

fix(data-warehouse): stop sending limit to chameleon profile search (#104155)

Tom Owers0cdcdabc1d8c
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/chameleon/chameleon.py b/products/warehouse_sources/backend/temporal/data_imports/sources/chameleon/chameleon.py
index a33ee306ddb8..e7261445995f 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/chameleon/chameleon.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/chameleon/chameleon.py
@@ -97,6 +97,10 @@ def validate_credentials(account_secret: str) -> tuple[bool, str | None]:
)
+def _page_params(config: ChameleonEndpointConfig) -> dict[str, Any]:
+ return {"limit": config.page_size} if config.page_size is not None else {}
+
+
def _standard_resource(
account_secret: str,
config: ChameleonEndpointConfig,
@@ -113,7 +117,7 @@ def _standard_resource(
"name": config.name,
"endpoint": {
"path": config.path,
- "params": {"limit": config.page_size},
+ "params": _page_params(config),
"paginator": ChameleonBeforeCursorPaginator(),
"data_selector": config.data_key,
},
@@ -184,7 +188,7 @@ def _fan_out_resource(
"name": parent_name,
"endpoint": {
"path": parent_config.path,
- "params": {"limit": parent_config.page_size},
+ "params": _page_params(parent_config),
"paginator": ChameleonBeforeCursorPaginator(),
"data_selector": parent_config.data_key,
},
@@ -198,7 +202,7 @@ def _fan_out_resource(
"path": f"{config.path}?id={{id}}",
"params": {
"id": {"type": "resolve", "resource": parent_name, "field": "id"},
- "limit": config.page_size,
+ **_page_params(config),
},
"paginator": ChameleonBeforeCursorPaginator(),
"data_selector": config.data_key,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/chameleon/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/chameleon/settings.py
index 76536a3735d4..910272ef5e98 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/chameleon/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/chameleon/settings.py
@@ -13,7 +13,9 @@ class ChameleonEndpointConfig:
# plural resource (e.g. {"segments": [...], "cursor": {...}}), which matches the endpoint name today.
data_key: str
partition_key: Optional[str] = "created_at" # stable creation timestamp present on every model
- page_size: int = 500 # Chameleon caps `limit` at 500
+ # Chameleon caps `limit` at 500 on the endpoints that document it. `None` marks an endpoint that
+ # documents no `limit`, so no `limit` is sent and Chameleon applies its own page size.
+ page_size: Optional[int] = 500
primary_keys: list[str] = field(default_factory=lambda: ["id"]) # Chameleon IDs are globally-unique ObjectIds
should_sync_default: bool = True
# Endpoints that require a parent record's `id` query param can only be listed one parent at a
@@ -26,7 +28,12 @@ class ChameleonEndpointConfig:
CHAMELEON_ENDPOINTS: dict[str, ChameleonEndpointConfig] = {
- "profiles": ChameleonEndpointConfig(name="profiles", path="/analyze/profiles", data_key="profiles"),
+ # /analyze/profiles is the User Profile search endpoint. Its documented parameters are only
+ # `segment_id`, `filters`, `filters_op` and `expand`, with no `limit`, and a request that sends
+ # `limit=500` is rejected with 422, which fails the whole table. Without `limit` Chameleon
+ # applies its own page size, and the paginator still follows `cursor.before` when the response
+ # carries one.
+ "profiles": ChameleonEndpointConfig(name="profiles", path="/analyze/profiles", data_key="profiles", page_size=None),
"companies": ChameleonEndpointConfig(name="companies", path="/analyze/companies", data_key="companies"),
"segments": ChameleonEndpointConfig(name="segments", path="/edit/segments", data_key="segments"),
"tours": ChameleonEndpointConfig(name="tours", path="/edit/tours", data_key="tours"),
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/chameleon/tests/test_chameleon.py b/products/warehouse_sources/backend/temporal/data_imports/sources/chameleon/tests/test_chameleon.py
index d9c3e1c6afac..7111b8f16e9c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/chameleon/tests/test_chameleon.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/chameleon/tests/test_chameleon.py
@@ -132,6 +132,26 @@ class TestStandardEndpointPagination:
assert snapshots[1]["params"]["before"] == "S2"
assert snapshots[2]["params"]["before"] == "S3"
+ @parameterized.expand(
+ [
+ # /analyze/profiles answers 422 to the `limit=500` the other list endpoints accept, so
+ # it must go out with no `limit` and let Chameleon pick the page size.
+ ("profiles_sends_no_limit", "profiles", None),
+ ("other_endpoints_keep_the_page_size", "segments", 500),
+ ]
+ )
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_page_size_is_only_sent_where_the_endpoint_accepts_it(
+ self, _name: str, endpoint: str, expected_limit: int | None, MockSession: mock.MagicMock
+ ) -> None:
+ session = MockSession.return_value
+ snapshots = _wire(session, [_response({endpoint: [{"id": "X1"}], "cursor": {}})])
+
+ rows = _rows(endpoint, _make_manager())
+
+ assert [r["id"] for r in rows] == ["X1"]
+ assert snapshots[0]["params"].get("limit") == expected_limit
+
@mock.patch(CLIENT_SESSION_PATCH)
def test_stops_when_cursor_missing(self, MockSession: mock.MagicMock) -> None:
session = MockSession.return_value