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.

feat(data-warehouse): add gridly projects, databases, grids and views tables (#110729)

Tom Owerse6b3dfe3fa15
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.md
index cca694ee074b..ceca13df4e5a 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
@@ -3840,10 +3840,10 @@ Today (2): `columns`, `records`
Diffed against: <https://www.gridly.com/docs/api/>
-- [ ] `views (GET /v1/views?gridId=)` — lookup for the view the synced records and columns belong to; also the only way to discover other views (high)
-- [ ] `grids (GET /v1/grids?dbId=)` — lookup resolving the grid that owns each view/record set (high)
-- [ ] `databases (GET /v1/databases?projectId=)` — lookup completing the project > database > grid > view hierarchy around synced records (high)
-- [ ] `projects (GET /v1/projects)` — top-level lookup for project names/IDs referenced by databases (high)
+- [x] `views (GET /v1/views?gridId=)` — lookup for the view the synced records and columns belong to; also the only way to discover other views (high)
+- [x] `grids (GET /v1/grids?dbId=)` — lookup resolving the grid that owns each view/record set (high)
+- [x] `databases (GET /v1/databases?projectId=)` — lookup completing the project > database > grid > view hierarchy around synced records (high)
+- [x] `projects (GET /v1/projects)` — top-level lookup for project names/IDs referenced by databases (high)
- [ ] `record histories (GET /v1/views/{viewId}/records/{recordId}/histories)` — per-cell change history - who changed which localization value and when (medium)
- [ ] `dependencies (GET /v1/views/{viewId}/dependencies)` — source-to-target column mapping that explains translation status columns (medium)
- [ ] `branches (GET /v1/branches?gridId=)` — branch metadata needed to interpret records synced from a branched grid (medium)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gridly/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gridly/canonical_descriptions.py
index 4f794dd8b621..39f071efa788 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gridly/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gridly/canonical_descriptions.py
@@ -24,4 +24,40 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"languageCode": "Language code for localization columns.",
},
},
+ "projects": {
+ "description": "Projects in the Gridly company, the top level of the project > database > grid > view hierarchy.",
+ "docs_url": "https://www.gridly.com/docs/api/#list-projects",
+ "columns": {
+ "id": "Unique identifier of the project.",
+ "name": "Name of the project.",
+ "description": "Description of the project.",
+ },
+ },
+ "databases": {
+ "description": "Databases in each Gridly project.",
+ "docs_url": "https://www.gridly.com/docs/api/#list-databases",
+ "columns": {
+ "id": "Unique identifier of the database.",
+ "name": "Name of the database.",
+ "projectId": "ID of the project that owns the database.",
+ },
+ },
+ "grids": {
+ "description": "Grids (sheets or tables) in each Gridly database.",
+ "docs_url": "https://www.gridly.com/docs/api/#list-grids",
+ "columns": {
+ "id": "Unique identifier of the grid.",
+ "name": "Name of the grid.",
+ "dbId": "ID of the database that owns the grid.",
+ },
+ },
+ "views": {
+ "description": "Views of each Gridly grid. A view displays all data of a grid or a subset of it, and is what the records and columns tables read from.",
+ "docs_url": "https://www.gridly.com/docs/api/#list-views",
+ "columns": {
+ "id": "Unique identifier of the view.",
+ "name": "Name of the view.",
+ "gridId": "ID of the grid the view belongs to.",
+ },
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gridly/gridly.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gridly/gridly.py
index 83ff25f2c249..3ba7fb687441 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gridly/gridly.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gridly/gridly.py
@@ -158,6 +158,34 @@ def _iter_columns(
yield columns
+def _iter_hierarchy(
+ session: requests.Session,
+ endpoint: str,
+ headers: dict[str, str],
+ logger: FilteringBoundLogger,
+) -> Iterator[list[dict[str, Any]]]:
+ """Walk the project > database > grid > view hierarchy down to `endpoint`.
+
+ Only `projects` lists without a parent, so each lower level fans out over every row of the
+ level above it, one unpaginated request per parent.
+ """
+ endpoint_config = GRIDLY_ENDPOINTS[endpoint]
+ url = f"{GRIDLY_BASE_URL}/{endpoint}"
+
+ if endpoint_config.parent is None or endpoint_config.parent_id_param is None:
+ rows = _fetch(session, url, {}, headers, logger).json()
+ if rows:
+ yield rows
+ return
+
+ parent_id_param = endpoint_config.parent_id_param
+ for parents in _iter_hierarchy(session, endpoint_config.parent, headers, logger):
+ for parent in parents:
+ rows = _fetch(session, url, {parent_id_param: parent["id"]}, headers, logger).json()
+ if rows:
+ yield [{**row, parent_id_param: parent["id"]} for row in rows]
+
+
def get_rows(
api_key: str,
view_id: str,
@@ -174,6 +202,8 @@ def get_rows(
yield from _iter_columns(session, view_id, headers, logger)
elif endpoint == "records":
yield from _iter_records(session, view_id, headers, logger, resumable_source_manager)
+ elif endpoint in ("projects", "databases", "grids", "views"):
+ yield from _iter_hierarchy(session, endpoint, headers, logger)
else:
raise ValueError(f"Unknown Gridly endpoint: {endpoint!r}")
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gridly/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gridly/settings.py
index 9129dc8c979c..eeacf183a802 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gridly/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gridly/settings.py
@@ -1,14 +1,20 @@
from dataclasses import dataclass, field
-@dataclass
+@dataclass(frozen=True)
class GridlyEndpointConfig:
name: str
# Record and column ids are unique within a view, and a Gridly source targets exactly one
- # view, so `id` is unique table-wide.
+ # view, so `id` is unique table-wide. Project, database, grid and view ids are global: each one
+ # is retrievable on its own via `GET /v1/<resource>/<id>`.
primary_keys: list[str] = field(default_factory=lambda: ["id"])
should_sync_default: bool = True
description: str | None = None
+ # Hierarchy endpoints are listed once per parent row. `parent_id_param` is the query param that
+ # scopes the list to one parent, and it's also written onto each row because the list
+ # responses don't carry the parent id.
+ parent: str | None = None
+ parent_id_param: str | None = None
GRIDLY_ENDPOINTS: dict[str, GridlyEndpointConfig] = {
@@ -25,6 +31,36 @@ GRIDLY_ENDPOINTS: dict[str, GridlyEndpointConfig] = {
name="columns",
description="Column definitions of the configured Gridly view. Full refresh only.",
),
+ # The company's project > database > grid > view hierarchy, walked top-down from `GET
+ # /v1/projects`. The list endpoints are unpaginated and return only id/name, so these are small
+ # full-refresh lookups. Off by default because a key scoped to a single view may not be able to
+ # list projects.
+ "projects": GridlyEndpointConfig(
+ name="projects",
+ should_sync_default=False,
+ description="Projects in the Gridly company. Full refresh only.",
+ ),
+ "databases": GridlyEndpointConfig(
+ name="databases",
+ should_sync_default=False,
+ description="Databases in every Gridly project, with the owning projectId. Full refresh only.",
+ parent="projects",
+ parent_id_param="projectId",
+ ),
+ "grids": GridlyEndpointConfig(
+ name="grids",
+ should_sync_default=False,
+ description="Grids in every Gridly database, with the owning dbId. Full refresh only.",
+ parent="databases",
+ parent_id_param="dbId",
+ ),
+ "views": GridlyEndpointConfig(
+ name="views",
+ should_sync_default=False,
+ description="Views of every Gridly grid, with the owning gridId. Full refresh only.",
+ parent="grids",
+ parent_id_param="gridId",
+ ),
}
ENDPOINTS = tuple(GRIDLY_ENDPOINTS.keys())
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gridly/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gridly/source.py
index e39b4b692085..e25c89dceec5 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gridly/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gridly/source.py
@@ -85,7 +85,7 @@ Find the **View ID** in Gridly by opening your grid, selecting a view, and openi
# calls `raise_for_status()`. Retrying can never satisfy a credential problem, so stop the
# sync. Match the stable status text and base host, not the per-request path/query.
"401 Client Error: Unauthorized for url: https://api.gridly.com": "Your Gridly API key is invalid or has been revoked. Create a new API key in your Gridly company settings, then reconnect.",
- "403 Client Error: Forbidden for url: https://api.gridly.com": "Your Gridly API key can't access this view. Grant the key access to the view (or use a Full Access key), then reconnect.",
+ "403 Client Error: Forbidden for url: https://api.gridly.com": "Your Gridly API key can't access this view or the projects, databases, and grids this table reads. Grant the key access (or use a Full Access key), then reconnect.",
}
def get_schemas(
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gridly/tests/test_gridly.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gridly/tests/test_gridly.py
index b4ad68481d1b..7a1af02d490c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gridly/tests/test_gridly.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gridly/tests/test_gridly.py
@@ -29,9 +29,9 @@ def _records_response(records: list[dict[str, Any]], total: int | None) -> mock.
return resp
-def _view_response(view: dict[str, Any]) -> mock.MagicMock:
+def _view_response(data: dict[str, Any] | list[dict[str, Any]]) -> mock.MagicMock:
resp = mock.MagicMock()
- resp.json.return_value = view
+ resp.json.return_value = data
resp.status_code = 200
resp.ok = True
return resp
@@ -149,6 +149,48 @@ class TestColumns:
assert list(get_rows("key", "view", "columns", mock.MagicMock(), _manager())) == []
+_HIERARCHY_RESPONSES: dict[tuple[str, tuple[tuple[str, Any], ...]], list[dict[str, Any]]] = {
+ ("/v1/projects", ()): [{"id": 1, "name": "P1"}, {"id": 2, "name": "P2"}],
+ ("/v1/databases", (("projectId", 1),)): [{"id": "db1", "name": "D1"}],
+ ("/v1/databases", (("projectId", 2),)): [],
+ ("/v1/grids", (("dbId", "db1"),)): [{"id": "g1", "name": "G1"}, {"id": "g2", "name": "G2"}],
+ ("/v1/views", (("gridId", "g1"),)): [{"id": "v1", "name": "Default view"}],
+ ("/v1/views", (("gridId", "g2"),)): [{"id": "v2", "name": "Default view"}, {"id": "v3", "name": "Fr"}],
+}
+
+
+def _hierarchy_get(url: str, params: dict[str, Any], **_kwargs: Any) -> mock.MagicMock:
+ return _view_response(_HIERARCHY_RESPONSES[(urlparse(url).path, tuple(sorted(params.items())))])
+
+
+class TestHierarchy:
+ @pytest.mark.parametrize(
+ "endpoint, expected_batches",
+ [
+ ("projects", [[{"id": 1, "name": "P1"}, {"id": 2, "name": "P2"}]]),
+ ("databases", [[{"id": "db1", "name": "D1", "projectId": 1}]]),
+ (
+ "grids",
+ [[{"id": "g1", "name": "G1", "dbId": "db1"}, {"id": "g2", "name": "G2", "dbId": "db1"}]],
+ ),
+ (
+ "views",
+ [
+ [{"id": "v1", "name": "Default view", "gridId": "g1"}],
+ [{"id": "v2", "name": "Default view", "gridId": "g2"}, {"id": "v3", "name": "Fr", "gridId": "g2"}],
+ ],
+ ),
+ ],
+ )
+ @mock.patch(f"{_MODULE}.make_tracked_session")
+ def test_walks_hierarchy_and_tags_rows_with_parent_id(self, mock_session, endpoint, expected_batches):
+ mock_session.return_value.get.side_effect = _hierarchy_get
+
+ batches = list(get_rows("key", "view", endpoint, mock.MagicMock(), _manager()))
+
+ assert batches == expected_batches
+
+
class TestRetries:
@mock.patch("time.sleep")
@mock.patch(f"{_MODULE}.PAGE_SIZE", 2)