Skip to content

Commit 67810f1

Browse files
tpellissierclaude
andcommitted
Fix PR review comments: docstrings, error docs, and create() validation
- Document type aliases in tables.create() columns param (#4) - Clarify SQL description in client namespace summary (#8) - Add :raises: for HttpError, ValidationError, ValueError across all operation methods (#6) - Fix query.sql() to document ValidationError instead of incorrect SQLParseError - Restore post-call validation in records.create() matching original client.create() behavior (#9) - Improve deprecated get() docstring with explicit guidance on when to use records.get() vs query.get() (#10) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 15e7287 commit 67810f1

4 files changed

Lines changed: 51 additions & 13 deletions

File tree

src/PowerPlatform/Dataverse/client.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class DataverseClient:
4848
Operations are organized into namespaces:
4949
5050
- ``client.records`` -- create, update, delete, get individual records
51-
- ``client.query`` -- paginated queries and SQL
51+
- ``client.query`` -- paginated OData queries and read-only SQL queries (via Web API ``?sql=`` parameter)
5252
- ``client.tables`` -- table and column metadata management
5353
5454
Example:
@@ -277,8 +277,10 @@ def get(
277277
) -> Union[Dict[str, Any], Iterable[List[Dict[str, Any]]]]:
278278
"""
279279
.. note::
280-
Deprecated. Use :meth:`~PowerPlatform.Dataverse.operations.records.RecordOperations.get`
281-
or :meth:`~PowerPlatform.Dataverse.operations.query.QueryOperations.get` instead.
280+
Deprecated. This method has been split into two:
281+
282+
- **Single record by ID** -- use ``client.records.get(table, record_id)``
283+
- **Query / filter multiple records** -- use ``client.query.get(table, filter=..., select=...)``
282284
283285
Fetch a single record by ID or query multiple records.
284286

src/PowerPlatform/Dataverse/operations/query.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ def get(
8888
dictionaries.
8989
:rtype: Iterable[list[dict[str, Any]]]
9090
91+
:raises ~PowerPlatform.Dataverse.core.errors.HttpError:
92+
If the Dataverse Web API returns an error.
93+
9194
Example:
9295
Query with filtering and pagination::
9396
@@ -140,10 +143,10 @@ def sql(self, sql: str) -> List[Dict[str, Any]]:
140143
rows match.
141144
:rtype: list[dict[str, Any]]
142145
143-
:raises ~PowerPlatform.Dataverse.core.errors.SQLParseError:
144-
If the SQL query uses unsupported syntax.
146+
:raises ~PowerPlatform.Dataverse.core.errors.ValidationError:
147+
If ``sql`` is not a string or is empty.
145148
:raises ~PowerPlatform.Dataverse.core.errors.HttpError:
146-
If the Web API returns an error.
149+
If the Dataverse Web API returns an error.
147150
148151
Example:
149152
Basic SQL query::

src/PowerPlatform/Dataverse/operations/records.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ def create(
7373
:rtype: str | list[str]
7474
7575
:raises TypeError: If ``data`` is not a dict or list[dict].
76+
:raises ~PowerPlatform.Dataverse.core.errors.HttpError:
77+
If the Dataverse Web API returns an error.
7678
7779
Example:
7880
Create a single record::
@@ -88,13 +90,19 @@ def create(
8890
])
8991
print(f"Created {len(guids)} accounts")
9092
"""
91-
if not isinstance(data, (dict, list)):
92-
raise TypeError("data must be dict or list[dict]")
9393
with self._client._scoped_odata() as od:
9494
entity_set = od._entity_set_from_schema_name(table)
9595
if isinstance(data, dict):
96-
return od._create(entity_set, table, data)
97-
return od._create_multiple(entity_set, table, data)
96+
rid = od._create(entity_set, table, data)
97+
if not isinstance(rid, str):
98+
raise TypeError("_create (single) did not return GUID string")
99+
return rid
100+
if isinstance(data, list):
101+
ids = od._create_multiple(entity_set, table, data)
102+
if not isinstance(ids, list) or not all(isinstance(x, str) for x in ids):
103+
raise TypeError("_create (multi) did not return list[str]")
104+
return ids
105+
raise TypeError("data must be dict or list[dict]")
98106

99107
# ------------------------------------------------------------------ update
100108

@@ -125,6 +133,8 @@ def update(
125133
126134
:raises TypeError: If ``ids`` is not str or list[str], or if ``changes``
127135
does not match the expected pattern.
136+
:raises ~PowerPlatform.Dataverse.core.errors.HttpError:
137+
If the Dataverse Web API returns an error.
128138
129139
Example:
130140
Single update::
@@ -188,6 +198,8 @@ def delete(
188198
:rtype: str | None
189199
190200
:raises TypeError: If ``ids`` is not str or list[str].
201+
:raises ~PowerPlatform.Dataverse.core.errors.HttpError:
202+
If the Dataverse Web API returns an error.
191203
192204
Example:
193205
Delete a single record::
@@ -237,6 +249,8 @@ def get(
237249
:rtype: dict[str, Any]
238250
239251
:raises TypeError: If ``record_id`` is not a string.
252+
:raises ~PowerPlatform.Dataverse.core.errors.HttpError:
253+
If the Dataverse Web API returns an error.
240254
241255
Example:
242256
Fetch a record with selected columns::

src/PowerPlatform/Dataverse/operations/tables.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,12 @@ def create(
6969
(e.g. ``"new_MyTestTable"``).
7070
:type table: str
7171
:param columns: Mapping of column schema names (with customization
72-
prefix) to their types. Supported types include ``"string"``,
73-
``"int"``, ``"decimal"``, ``"float"``, ``"datetime"``, ``"bool"``,
74-
``"file"``, and ``Enum`` subclasses (for local option sets).
72+
prefix) to their types. Supported types include ``"string"``
73+
(or ``"text"``), ``"int"`` (or ``"integer"``), ``"decimal"``
74+
(or ``"money"``), ``"float"`` (or ``"double"``), ``"datetime"``
75+
(or ``"date"``), ``"bool"`` (or ``"boolean"``), ``"file"``, and
76+
``Enum`` subclasses
77+
(for local option sets).
7578
:type columns: dict[str, Any]
7679
:param solution: Optional solution unique name that should own the new
7780
table. When omitted the table is created in the default solution.
@@ -88,6 +91,9 @@ def create(
8891
8992
:raises ~PowerPlatform.Dataverse.core.errors.MetadataError:
9093
If table creation fails or the table already exists.
94+
:raises ~PowerPlatform.Dataverse.core.errors.HttpError:
95+
If the Dataverse Web API returns an error.
96+
:raises ValueError: If a column type string is not recognized.
9197
9298
Example:
9399
Create a table with simple columns::
@@ -128,6 +134,8 @@ def delete(self, table: str) -> None:
128134
129135
:raises ~PowerPlatform.Dataverse.core.errors.MetadataError:
130136
If the table does not exist or deletion fails.
137+
:raises ~PowerPlatform.Dataverse.core.errors.HttpError:
138+
If the Dataverse Web API returns an error.
131139
132140
.. warning::
133141
This operation is irreversible and will delete all records in the
@@ -154,6 +162,9 @@ def get(self, table: str) -> Optional[Dict[str, Any]]:
154162
Returns None if the table is not found.
155163
:rtype: dict[str, Any] | None
156164
165+
:raises ~PowerPlatform.Dataverse.core.errors.HttpError:
166+
If the Dataverse Web API returns an error.
167+
157168
Example::
158169
159170
info = client.tables.get("new_MyTestTable")
@@ -172,6 +183,9 @@ def list(self) -> List[Dict[str, Any]]:
172183
:return: List of EntityDefinition metadata dictionaries.
173184
:rtype: list[dict[str, Any]]
174185
186+
:raises ~PowerPlatform.Dataverse.core.errors.HttpError:
187+
If the Dataverse Web API returns an error.
188+
175189
Example::
176190
177191
tables = client.tables.list()
@@ -202,6 +216,9 @@ def add_columns(
202216
203217
:raises ~PowerPlatform.Dataverse.core.errors.MetadataError:
204218
If the table does not exist.
219+
:raises ~PowerPlatform.Dataverse.core.errors.HttpError:
220+
If the Dataverse Web API returns an error.
221+
:raises ValueError: If a column type string is not recognized.
205222
206223
Example::
207224
@@ -235,6 +252,8 @@ def remove_columns(
235252
236253
:raises ~PowerPlatform.Dataverse.core.errors.MetadataError:
237254
If the table or a specified column does not exist.
255+
:raises ~PowerPlatform.Dataverse.core.errors.HttpError:
256+
If the Dataverse Web API returns an error.
238257
239258
Example::
240259

0 commit comments

Comments
 (0)