Add extended table metadata retrieval and models for columns and option sets#2
Add extended table metadata retrieval and models for columns and option sets#2
Conversation
…on sets - Implemented methods to fetch detailed metadata for tables, including columns and relationships. - Introduced `ColumnMetadata`, `OptionItem`, and `OptionSetInfo` models to represent column and option set data structures. - Updated `get` method in `TableOperations` to support optional parameters for including columns and relationships in the response. - Enhanced tests to cover new functionality and ensure backward compatibility. This update improves the SDK's ability to interact with Dataverse metadata, providing richer data for developers.
|
Codex Review: Didn't find any major issues. Keep it up! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Co-authored-by: maksii <1761348+maksii@users.noreply.github.com>
Fix spurious `columns_created` in `get()` result and reduce cyclomatic complexity
- Introduced new test data fixtures in `tests/fixtures/test_data.py` for various metadata attributes, including columns, option sets, and relationships. - Updated `tests/unit/models/test_metadata.py` to utilize the new fixtures for testing `ColumnMetadata` and `OptionSetInfo` classes, improving test coverage for primary name columns, picklist columns, and status/state option sets. - Enhanced `tests/unit/test_tables_operations.py` to incorporate fixtures for table operations, ensuring accurate testing of column retrieval, relationship listing, and table metadata. - Refactored existing tests to replace hardcoded data with structured test data from the new fixtures, promoting maintainability and clarity in test cases.
There was a problem hiding this comment.
Pull request overview
This PR extends the Dataverse SDK’s table metadata APIs to support richer metadata retrieval (columns, relationships, and option sets) and adds new metadata models plus corresponding unit tests.
Changes:
- Added extended table metadata retrieval to
TableOperations.get()viaselect,include_columns, andinclude_relationships. - Introduced metadata models (
ColumnMetadata,OptionItem,OptionSetInfo) and added extensive fixtures/tests for columns and option sets. - Implemented new OData metadata helpers for table metadata, columns, relationships, and column option sets.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/PowerPlatform/Dataverse/operations/tables.py |
Extends public table metadata APIs (get/columns/relationships/option sets). |
src/PowerPlatform/Dataverse/data/_odata.py |
Adds OData helper methods for metadata retrieval (tables, columns, option sets, relationships). |
src/PowerPlatform/Dataverse/models/metadata.py |
Adds dataclass models for column and option set metadata. |
src/PowerPlatform/Dataverse/common/constants.py |
Adds OData type constants used for attribute-type casting in metadata calls. |
tests/unit/test_tables_operations.py |
Expands table operations tests to cover new metadata functionality and backward compatibility. |
tests/unit/models/test_metadata.py |
New unit tests validating metadata model parsing. |
tests/fixtures/test_data.py |
Adds realistic fixtures for attributes, option sets, relationships, and table list entries. |
tests/fixtures/__init__.py |
Initializes fixtures as a package. |
README.md |
Documents new metadata retrieval APIs with examples. |
.claude/skills/dataverse-sdk-use/SKILL.md |
Updates skill documentation with new metadata retrieval examples. |
Comments suppressed due to low confidence (3)
src/PowerPlatform/Dataverse/data/_odata.py:1534
- _get_table_metadata() expands
Attributes/ relationship collections without projecting fields (no nested$select). ExpandingAttributesin particular can return very large payloads for common entities, which can maketables.get(..., include_columns=True)slow/heavy. Consider adding nested$selectfor expanded collections (or reusing the more selective_get_table_columnsendpoint for columns) so the default extended-get remains practical on large schemas.
expand_parts: List[str] = []
if include_attributes:
expand_parts.append("Attributes")
if include_one_to_many:
expand_parts.append("OneToManyRelationships")
if include_many_to_one:
expand_parts.append("ManyToOneRelationships")
if include_many_to_many:
expand_parts.append("ManyToManyRelationships")
src/PowerPlatform/Dataverse/operations/tables.py:368
- The get_column_options() docstring says it only supports Picklist/MultiSelect/Boolean columns, but the implementation (_get_column_optionset) also supports Status and State attribute types (and unit tests exercise those). Please update the docstring to include Status/State so the public API docs match behavior.
"""Get option set values for a Picklist, MultiSelect, or Boolean column.
This method retrieves the available choices for a column that uses an
option set. For Picklist and MultiSelect columns, the options are the
defined choice values. For Boolean columns, the result contains the
True and False option labels.
src/PowerPlatform/Dataverse/data/_odata.py:1660
- _get_column_optionset() uses
$expand=OptionSet,GlobalOptionSetwithout a nested$select. This can significantly increase payload size and may omit fields you actually need (e.g., Options / TrueOption / FalseOption) depending on server defaults. Consider using a nested expand with an explicit select (similar to the existing picklist fetch logic earlier in this file that usesOptionSet($select=Options)) to keep responses smaller and more reliable.
base = f"{self.api}/EntityDefinitions(LogicalName='{table_lower}')/Attributes(LogicalName='{column_lower}')"
params = {"$select": "LogicalName", "$expand": "OptionSet,GlobalOptionSet"}
for cast_type in [
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Updated the docstring to clarify the types of columns supported, including Picklist, MultiSelect, Boolean, Status, and State. - Improved descriptions of the return values for better understanding of the method's functionality.
…ty select list in TableOperations
Add extended table metadata retrieval and models for columns and option sets
ColumnMetadata,OptionItem, andOptionSetInfomodels to represent column and option set data structures.getmethod inTableOperationsto support optional parameters for including columns and relationships in the response.This update improves the SDK's ability to interact with Dataverse metadata, providing richer data for developers.