Skip to content

Commit c354931

Browse files
tpellissierclaude
andcommitted
Handle Enum/IntEnum in _format_value, fix README namespace description
- Add Enum handling before int check in _format_value (IntEnum is a subclass of int, so str(IntEnum.VAL) gives the name not the value) - Add unit tests for IntEnum and str Enum formatting - Fix README namespaces row to include OData queries under records Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 87b4b44 commit c354931

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ The SDK provides a simple, pythonic interface for Dataverse operations:
115115
|---------|-------------|
116116
| **DataverseClient** | Main entry point; provides `records`, `query`, `tables`, and `files` namespaces |
117117
| **Context Manager** | Use `with DataverseClient(...) as client:` for automatic cleanup and HTTP connection pooling |
118-
| **Namespaces** | Operations are organized into `client.records` (CRUD), `client.query` (QueryBuilder & SQL), `client.tables` (metadata), and `client.files` (file uploads) |
118+
| **Namespaces** | Operations are organized into `client.records` (CRUD & OData queries), `client.query` (QueryBuilder & SQL), `client.tables` (metadata), and `client.files` (file uploads) |
119119
| **Records** | Dataverse records represented as Python dictionaries with column schema names |
120120
| **Schema names** | Use table schema names (`"account"`, `"new_MyTestTable"`) and column schema names (`"name"`, `"new_MyTestColumn"`). See: [Table definitions in Microsoft Dataverse](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/entity-metadata) |
121121
| **Bulk Operations** | Efficient bulk processing for multiple records with automatic optimization |

src/PowerPlatform/Dataverse/models/filters.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
from __future__ import annotations
3434

35+
import enum
3536
import uuid
3637
from datetime import date, datetime, timezone
3738
from typing import Any, Sequence
@@ -76,6 +77,9 @@ def _format_value(value: Any) -> str:
7677
# bool MUST be checked before int (bool is a subclass of int)
7778
if isinstance(value, bool):
7879
return "true" if value else "false"
80+
# Enum/IntEnum MUST be checked before int (IntEnum is a subclass of int)
81+
if isinstance(value, enum.Enum):
82+
return _format_value(value.value)
7983
if isinstance(value, int):
8084
return str(value)
8185
if isinstance(value, float):

tests/unit/models/test_filters.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,24 @@ def test_float(self):
5959
def test_float_integer_value(self):
6060
self.assertEqual(_format_value(1000000.0), "1000000.0")
6161

62+
def test_int_enum(self):
63+
from enum import IntEnum
64+
65+
class Priority(IntEnum):
66+
LOW = 1
67+
HIGH = 2
68+
69+
self.assertEqual(_format_value(Priority.HIGH), "2")
70+
self.assertEqual(_format_value(Priority.LOW), "1")
71+
72+
def test_str_enum(self):
73+
from enum import Enum
74+
75+
class Color(Enum):
76+
RED = "red"
77+
78+
self.assertEqual(_format_value(Color.RED), "'red'")
79+
6280
def test_string(self):
6381
self.assertEqual(_format_value("hello"), "'hello'")
6482

0 commit comments

Comments
 (0)