Preserve @odata keys when normalizing record keys#86
Preserve @odata keys when normalizing record keys#86MrPoopey wants to merge 2 commits intomicrosoft:mainfrom
Conversation
|
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where OData annotation keys were being incorrectly lowercased. The _lowercase_keys helper function now preserves case-sensitive OData keys (like @odata.bind) while still normalizing Dataverse attribute names to lowercase.
Changes:
- Modified
_lowercase_keysto detect and preserve OData annotation keys by checking for "@OData" substring - Updated docstrings and inline comments to reflect the new behavior
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def _lowercase_keys(record: Dict[str, Any]) -> Dict[str, Any]: | ||
| """Convert all dictionary keys to lowercase for case-insensitive column names. | ||
| """Normalize dictionary keys to lowercase for case-insensitive column names. | ||
|
|
||
| Dataverse LogicalNames for attributes are stored lowercase, but users may | ||
| provide PascalCase names (matching SchemaName). This normalizes the input. | ||
| This function lowercases all string keys except OData annotation keys, | ||
| which must remain case-sensitive. | ||
| """ | ||
| if not isinstance(record, dict): | ||
| return record | ||
| return {k.lower() if isinstance(k, str) else k: v for k, v in record.items()} | ||
|
|
||
| new_record = {} | ||
|
|
||
| # Preserve OData annotation keys as they are case sensitive | ||
| for k, v in record.items(): | ||
| if isinstance(k, str) and "@odata" in k: | ||
| new_record[k] = v | ||
| else: | ||
| new_record[k.lower() if isinstance(k, str) else k] = v | ||
| return new_record |
There was a problem hiding this comment.
The _lowercase_keys function lacks test coverage for the new behavior of preserving OData annotation keys. Consider adding tests that verify OData keys like "@odata.bind", "@odata.type", and "@odata.nextLink" are preserved with their original casing while regular attribute keys are lowercased.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
The _lowercase_keys helper function previously lowercases all string keys which unintentionally breaks OData keys such as @odata.bind. These keys are case sensitive and must remain unchanged for Dataverse to interpret them correctly.