feat: DM-3945 add table reference CRUD client APIs#40
Conversation
Wraps the new `/api/table-references/` endpoints from datamasque/datamasque!3534, mirroring the existing connection and discovery-config-library client patterns. - New `TableReferenceClient` mixin: list, get, get-by-name, create, update, create-or-update, delete by id/name. - New `TableReference`, `TableReferenceOptions` and `TableReferenceFormat` models. `connection` accepts a `ConnectionId` or a whole `ConnectionConfig`, as run requests do. - The list endpoint is unpaginated and shares the detail serializer, so a by-name lookup needs a single request; the endpoint takes no name filter, so the match is made client-side. - Deletes archive rather than remove, which frees the name for reuse. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
|
||
| @field_validator("connection", mode="before") | ||
| @classmethod | ||
| def _unwrap_connection(cls, value: Any) -> Any: |
There was a problem hiding this comment.
| def _unwrap_connection(cls, value: Any) -> Any: | |
| def _unwrap_connection(cls, value: object) -> object: |
|
|
||
|
|
||
| @pytest.fixture | ||
| def sample_table_reference_list_response() -> list[dict[str, Any]]: |
There was a problem hiding this comment.
Change Any to object here and elsewhere in module.
| """The string in the source data to read as a null value, or `None` to read no value as null.""" | ||
|
|
||
|
|
||
| class TableReference(BaseModel): |
There was a problem hiding this comment.
Do we want to strip server-only fields, the same way _strip_server_only_fields does for connections?
There was a problem hiding this comment.
Checked — unlike connections there's no secret/write-only field on this model (no password equivalent). Server response only ever contains name/connection/source/options/id/created/modified, all modeled; id/created/modified already excluded from request bodies via Field(exclude=True). No stripping needed here.
|
|
||
| * file connection — a path to the file within the connection's fileset. | ||
| The format comes from `options.format`, never from the path's suffix. | ||
| * database connection — a dotted, schema-qualified ``schema.table`` reference. |
There was a problem hiding this comment.
| * database connection — a dotted, schema-qualified ``schema.table`` reference. | |
| * database connection — a dotted, schema-qualified `schema.table` reference. |
| if table_reference.id is None: | ||
| raise ValueError("Cannot update a table reference that has not been created yet (id is None)") | ||
|
|
||
| data = table_reference.model_dump(exclude_none=True, by_alias=True, mode="json") |
There was a problem hiding this comment.
exclude_none=True will cause null_str to be omitted from the payload.
| data = table_reference.model_dump(exclude_none=True, by_alias=True, mode="json") | |
| data = table_reference.model_dump(by_alias=True, mode="json") | |
| if data.get("options") is None: | |
| data.pop("options", None) |
- Use `object` instead of `Any` in the new model validator and test annotations. - Fix docstring formatting for the schema.table reference. - Stop using `exclude_none=True` for request payloads: it silently dropped `options.null_string` (and any other nested `None`) instead of just omitting a wholly-unset `options`. Now only the `options` key itself is dropped when `None`, so explicit `None` values inside it (e.g. `null_string`) are still sent. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Match discovery_configs.py's convention: a malformed server response (missing id) raises DataMasqueApiError with the triggering response attached, not the bare DataMasqueException, so callers catching DataMasqueApiError for API-shape problems catch this too. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Adds Python client support for the
TableReferenceobject introduced by DM-3945 / datamasque/datamasque!3534.What
TableReferenceClientmixin over/api/table-references/:list_table_references,get_table_reference,get_table_reference_by_name,create_table_reference,update_table_reference,create_or_update_table_reference,delete_table_reference_by_id_if_exists,delete_table_reference_by_name_if_exists.TableReference,TableReferenceOptions,TableReferenceFormat(csv/parquet),TableReferenceId.connectionaccepts aConnectionIdor a wholeConnectionConfig(itsidis extracted), matchingMaskingRunRequest; aconnection_idproperty narrows the type back for reads.datamasque.client; mixed intoDataMasqueClient;HISTORY.rstentry and version bump to1.1.8.Notes on matching the server
get_table_reference_by_nameneeds one request rather than two. There is noname_exactfilter server-side, so the name match is made client-side over the full listing.create_or_update_table_referencekeys on the name.optionsare omitted from the request entirely when unset (the server keeps what it has stored) and replaced wholesale when set. They are sent regardless of the connection's type, mirroring the server, which accepts and stores them for database connections too.sourceis not validated client-side. Its meaning is discriminated by the connection's own type (file path vs. dottedschema.table), and the file format is the explicitoptions.formatchoice rather than being inferred from the path's suffix.Testing
21 new tests; full suite (421) green.
make lintclean (ruff, ruff format, mypy).🤖 Generated with Claude Code