Skip to content

Commit e92516d

Browse files
jfrench9claude
andauthored
Refactor materialization operations to use MaterializeOp model (#92)
## Summary Refactors the materialization operation logic to use a dedicated `MaterializeOp` model, replacing inline/ad-hoc parameter handling with a structured, typed approach. This aligns materialization operations with the existing pattern used by other graph operations (e.g., `UpgradeTierOp`). ## Key Accomplishments - **New `MaterializeOp` model**: Introduced a dedicated Pydantic/data model (`materialize_op.py`) that encapsulates all parameters and validation logic for materialization operations, improving type safety and maintainability. - **New `UpgradeTierOpNewTier` model**: Added a supporting model for the upgrade tier operation's new tier representation, further strengthening the type system across graph operations. - **New `DatabaseHealthResponse` model**: Added a structured model for database health responses (93 lines of new model code), replacing loosely-typed response handling. - **Simplified `op_materialize.py`**: Reduced the materialization operation module by ~100 lines by delegating parameter construction and validation to the new `MaterializeOp` model, significantly improving readability and reducing duplication. - **Updated `graph_client.py`**: Adjusted the graph client to work with the new model-based approach for materialization calls. - **Exported new models**: Updated `models/__init__.py` to expose the new models as part of the public API. ## Breaking Changes - **API surface change**: Consumers that previously constructed materialization operation parameters inline will need to migrate to using the `MaterializeOp` model. The method signatures in the graph client have been updated accordingly. - **Model imports**: New models are now available via `robosystems_client.models`; any code importing directly from internal modules may need path updates. ## Testing Notes - Existing materialization tests (`test_materialization_client.py`) have been updated to reflect the new model-based interface. - Verify that all materialization workflows (create, update, delete) function correctly end-to-end with the new `MaterializeOp` model. - Validate that the `DatabaseHealthResponse` model correctly deserializes health check responses from the API. ## Infrastructure Considerations - No new dependencies introduced; the new models follow existing patterns and frameworks already in use. - Downstream services or CI pipelines that depend on the materialization client interface should be validated against the updated method signatures. - This is a stepping stone toward a consistent model-driven pattern for all graph operations, making future operation additions more straightforward. --- 🤖 Generated with [Claude Code](https://claude.ai/code) **Branch Info:** - Source: `refactor/additional-graph-ops` - Target: `main` - Type: feature Co-Authored-By: Claude <noreply@anthropic.com>
2 parents 1f9df4e + 223c394 commit e92516d

8 files changed

Lines changed: 260 additions & 123 deletions

File tree

‎robosystems_client/api/graph_operations/op_materialize.py‎

Lines changed: 18 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from ... import errors
88
from ...client import AuthenticatedClient, Client
99
from ...models.http_validation_error import HTTPValidationError
10+
from ...models.materialize_op import MaterializeOp
1011
from ...models.operation_envelope import OperationEnvelope
1112
from ...models.operation_error import OperationError
1213
from ...types import UNSET, Response, Unset
@@ -15,47 +16,24 @@
1516
def _get_kwargs(
1617
graph_id: str,
1718
*,
18-
force: bool | Unset = False,
19-
rebuild: bool | Unset = False,
20-
ignore_errors: bool | Unset = True,
21-
dry_run: bool | Unset = False,
22-
source: None | str | Unset = UNSET,
23-
materialize_embeddings: bool | Unset = False,
19+
body: MaterializeOp,
2420
idempotency_key: None | str | Unset = UNSET,
2521
) -> dict[str, Any]:
2622
headers: dict[str, Any] = {}
2723
if not isinstance(idempotency_key, Unset):
2824
headers["Idempotency-Key"] = idempotency_key
2925

30-
params: dict[str, Any] = {}
31-
32-
params["force"] = force
33-
34-
params["rebuild"] = rebuild
35-
36-
params["ignore_errors"] = ignore_errors
37-
38-
params["dry_run"] = dry_run
39-
40-
json_source: None | str | Unset
41-
if isinstance(source, Unset):
42-
json_source = UNSET
43-
else:
44-
json_source = source
45-
params["source"] = json_source
46-
47-
params["materialize_embeddings"] = materialize_embeddings
48-
49-
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
50-
5126
_kwargs: dict[str, Any] = {
5227
"method": "post",
5328
"url": "/v1/graphs/{graph_id}/operations/materialize".format(
5429
graph_id=quote(str(graph_id), safe=""),
5530
),
56-
"params": params,
5731
}
5832

33+
_kwargs["json"] = body.to_dict()
34+
35+
headers["Content-Type"] = "application/json"
36+
5937
_kwargs["headers"] = headers
6038
return _kwargs
6139

@@ -125,33 +103,20 @@ def sync_detailed(
125103
graph_id: str,
126104
*,
127105
client: AuthenticatedClient,
128-
force: bool | Unset = False,
129-
rebuild: bool | Unset = False,
130-
ignore_errors: bool | Unset = True,
131-
dry_run: bool | Unset = False,
132-
source: None | str | Unset = UNSET,
133-
materialize_embeddings: bool | Unset = False,
106+
body: MaterializeOp,
134107
idempotency_key: None | str | Unset = UNSET,
135108
) -> Response[Any | HTTPValidationError | OperationEnvelope | OperationError]:
136109
"""Materialize Graph
137110
138111
Materialize graph from staging tables or extensions OLTP.
139112
140-
Delegates to the existing materialize_graph handler which handles
141-
distributed locking, source routing, and Dagster/direct dispatch.
142-
143113
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
144114
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
145115
146116
Args:
147117
graph_id (str):
148-
force (bool | Unset): Default: False.
149-
rebuild (bool | Unset): Default: False.
150-
ignore_errors (bool | Unset): Default: True.
151-
dry_run (bool | Unset): Default: False.
152-
source (None | str | Unset):
153-
materialize_embeddings (bool | Unset): Default: False.
154118
idempotency_key (None | str | Unset):
119+
body (MaterializeOp): Body for the materialize operation.
155120
156121
Raises:
157122
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
@@ -163,12 +128,7 @@ def sync_detailed(
163128

164129
kwargs = _get_kwargs(
165130
graph_id=graph_id,
166-
force=force,
167-
rebuild=rebuild,
168-
ignore_errors=ignore_errors,
169-
dry_run=dry_run,
170-
source=source,
171-
materialize_embeddings=materialize_embeddings,
131+
body=body,
172132
idempotency_key=idempotency_key,
173133
)
174134

@@ -183,33 +143,20 @@ def sync(
183143
graph_id: str,
184144
*,
185145
client: AuthenticatedClient,
186-
force: bool | Unset = False,
187-
rebuild: bool | Unset = False,
188-
ignore_errors: bool | Unset = True,
189-
dry_run: bool | Unset = False,
190-
source: None | str | Unset = UNSET,
191-
materialize_embeddings: bool | Unset = False,
146+
body: MaterializeOp,
192147
idempotency_key: None | str | Unset = UNSET,
193148
) -> Any | HTTPValidationError | OperationEnvelope | OperationError | None:
194149
"""Materialize Graph
195150
196151
Materialize graph from staging tables or extensions OLTP.
197152
198-
Delegates to the existing materialize_graph handler which handles
199-
distributed locking, source routing, and Dagster/direct dispatch.
200-
201153
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
202154
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
203155
204156
Args:
205157
graph_id (str):
206-
force (bool | Unset): Default: False.
207-
rebuild (bool | Unset): Default: False.
208-
ignore_errors (bool | Unset): Default: True.
209-
dry_run (bool | Unset): Default: False.
210-
source (None | str | Unset):
211-
materialize_embeddings (bool | Unset): Default: False.
212158
idempotency_key (None | str | Unset):
159+
body (MaterializeOp): Body for the materialize operation.
213160
214161
Raises:
215162
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
@@ -222,12 +169,7 @@ def sync(
222169
return sync_detailed(
223170
graph_id=graph_id,
224171
client=client,
225-
force=force,
226-
rebuild=rebuild,
227-
ignore_errors=ignore_errors,
228-
dry_run=dry_run,
229-
source=source,
230-
materialize_embeddings=materialize_embeddings,
172+
body=body,
231173
idempotency_key=idempotency_key,
232174
).parsed
233175

@@ -236,33 +178,20 @@ async def asyncio_detailed(
236178
graph_id: str,
237179
*,
238180
client: AuthenticatedClient,
239-
force: bool | Unset = False,
240-
rebuild: bool | Unset = False,
241-
ignore_errors: bool | Unset = True,
242-
dry_run: bool | Unset = False,
243-
source: None | str | Unset = UNSET,
244-
materialize_embeddings: bool | Unset = False,
181+
body: MaterializeOp,
245182
idempotency_key: None | str | Unset = UNSET,
246183
) -> Response[Any | HTTPValidationError | OperationEnvelope | OperationError]:
247184
"""Materialize Graph
248185
249186
Materialize graph from staging tables or extensions OLTP.
250187
251-
Delegates to the existing materialize_graph handler which handles
252-
distributed locking, source routing, and Dagster/direct dispatch.
253-
254188
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
255189
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
256190
257191
Args:
258192
graph_id (str):
259-
force (bool | Unset): Default: False.
260-
rebuild (bool | Unset): Default: False.
261-
ignore_errors (bool | Unset): Default: True.
262-
dry_run (bool | Unset): Default: False.
263-
source (None | str | Unset):
264-
materialize_embeddings (bool | Unset): Default: False.
265193
idempotency_key (None | str | Unset):
194+
body (MaterializeOp): Body for the materialize operation.
266195
267196
Raises:
268197
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
@@ -274,12 +203,7 @@ async def asyncio_detailed(
274203

275204
kwargs = _get_kwargs(
276205
graph_id=graph_id,
277-
force=force,
278-
rebuild=rebuild,
279-
ignore_errors=ignore_errors,
280-
dry_run=dry_run,
281-
source=source,
282-
materialize_embeddings=materialize_embeddings,
206+
body=body,
283207
idempotency_key=idempotency_key,
284208
)
285209

@@ -292,33 +216,20 @@ async def asyncio(
292216
graph_id: str,
293217
*,
294218
client: AuthenticatedClient,
295-
force: bool | Unset = False,
296-
rebuild: bool | Unset = False,
297-
ignore_errors: bool | Unset = True,
298-
dry_run: bool | Unset = False,
299-
source: None | str | Unset = UNSET,
300-
materialize_embeddings: bool | Unset = False,
219+
body: MaterializeOp,
301220
idempotency_key: None | str | Unset = UNSET,
302221
) -> Any | HTTPValidationError | OperationEnvelope | OperationError | None:
303222
"""Materialize Graph
304223
305224
Materialize graph from staging tables or extensions OLTP.
306225
307-
Delegates to the existing materialize_graph handler which handles
308-
distributed locking, source routing, and Dagster/direct dispatch.
309-
310226
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
311227
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
312228
313229
Args:
314230
graph_id (str):
315-
force (bool | Unset): Default: False.
316-
rebuild (bool | Unset): Default: False.
317-
ignore_errors (bool | Unset): Default: True.
318-
dry_run (bool | Unset): Default: False.
319-
source (None | str | Unset):
320-
materialize_embeddings (bool | Unset): Default: False.
321231
idempotency_key (None | str | Unset):
232+
body (MaterializeOp): Body for the materialize operation.
322233
323234
Raises:
324235
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
@@ -332,12 +243,7 @@ async def asyncio(
332243
await asyncio_detailed(
333244
graph_id=graph_id,
334245
client=client,
335-
force=force,
336-
rebuild=rebuild,
337-
ignore_errors=ignore_errors,
338-
dry_run=dry_run,
339-
source=source,
340-
materialize_embeddings=materialize_embeddings,
246+
body=body,
341247
idempotency_key=idempotency_key,
342248
)
343249
).parsed

‎robosystems_client/clients/graph_client.py‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,13 +333,17 @@ def materialize(
333333

334334
client = self._get_authenticated_client()
335335

336+
from ..models.materialize_op import MaterializeOp
337+
336338
response = materialize_graph(
337339
graph_id=graph_id,
338340
client=client,
339-
ignore_errors=options.ignore_errors,
340-
rebuild=options.rebuild,
341-
force=options.force,
342-
materialize_embeddings=options.materialize_embeddings,
341+
body=MaterializeOp(
342+
ignore_errors=options.ignore_errors,
343+
rebuild=options.rebuild,
344+
force=options.force,
345+
materialize_embeddings=options.materialize_embeddings,
346+
),
343347
)
344348

345349
# Handle non-success status codes

‎robosystems_client/models/__init__.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@
215215
from .login_request import LoginRequest
216216
from .logout_user_response_logoutuser import LogoutUserResponseLogoutuser
217217
from .manual_line_item_request import ManualLineItemRequest
218+
from .materialize_op import MaterializeOp
218219
from .mcp_tool_call import MCPToolCall
219220
from .mcp_tool_call_arguments import MCPToolCallArguments
220221
from .mcp_tools_response import MCPToolsResponse
@@ -366,6 +367,7 @@
366367
from .update_user_request import UpdateUserRequest
367368
from .upgrade_subscription_request import UpgradeSubscriptionRequest
368369
from .upgrade_tier_op import UpgradeTierOp
370+
from .upgrade_tier_op_new_tier import UpgradeTierOpNewTier
369371
from .user_graphs_response import UserGraphsResponse
370372
from .user_response import UserResponse
371373
from .validation_error import ValidationError
@@ -563,6 +565,7 @@
563565
"LoginRequest",
564566
"LogoutUserResponseLogoutuser",
565567
"ManualLineItemRequest",
568+
"MaterializeOp",
566569
"MCPToolCall",
567570
"MCPToolCallArguments",
568571
"MCPToolsResponse",
@@ -692,6 +695,7 @@
692695
"UpdateUserRequest",
693696
"UpgradeSubscriptionRequest",
694697
"UpgradeTierOp",
698+
"UpgradeTierOpNewTier",
695699
"UserGraphsResponse",
696700
"UserResponse",
697701
"ValidationError",

0 commit comments

Comments
 (0)