Skip to content

Commit 8baae12

Browse files
fix/#652 (#668) fixes pydantic warnings and minimum pins to pydantic >=2.0
* type(model).model_fields accesses the attribute on the class, which is the correct way per Pydantic v2.11+. * all instances use type(model).model_fields correctly. * Update pydantic version constraint to >=2.11 * Update pydantic version to >=2.11 in pyproject.toml * Added test_pydantic_version that ensures correct pydantic version to handle model_fields. * made all the structural changes. * Fixed some pre-commit linting errors. --------- Co-authored-by: vaibhavsingh-materialplus <Vaibhav.Singh@materialplus.io>
1 parent 558de8a commit 8baae12

3 files changed

Lines changed: 17 additions & 6 deletions

File tree

burr/integrations/pydantic.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@
5151

5252
def model_to_dict(model: pydantic.BaseModel, include: Optional[List[str]] = None) -> dict:
5353
"""Utility function to convert a pydantic model to a dictionary."""
54-
keys = model.model_fields.keys()
55-
keys = keys if include is None else [item for item in include if item in model.model_fields]
54+
keys = type(model).model_fields.keys()
55+
keys = (
56+
keys if include is None else [item for item in include if item in type(model).model_fields]
57+
)
5658
return {key: getattr(model, key) for key in keys}
5759

5860

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ tests = [
8989
"langchain_core",
9090
"langchain_community",
9191
"pandas",
92-
"pydantic[email]",
92+
"pydantic[email]>=2.0",
9393
"pyarrow",
9494
"apache-burr[aiosqlite]",
9595
"apache-burr[asyncpg]",
@@ -120,7 +120,7 @@ documentation = [
120120
]
121121

122122
tracking-client = [
123-
"pydantic>1"
123+
"pydantic>=2.0"
124124
]
125125

126126
tracking-client-s3 = [
@@ -141,7 +141,7 @@ tracking-server = [
141141
"click",
142142
"fastapi",
143143
"uvicorn",
144-
"pydantic",
144+
"pydantic>=2.0",
145145
"pydantic-settings",
146146
"fastapi-pagination",
147147
"fastapi-utils",
@@ -153,7 +153,7 @@ tracking-server = [
153153
]
154154

155155
pydantic = [
156-
"pydantic"
156+
"pydantic>=2.0"
157157
]
158158

159159
haystack = [

tests/integrations/test_burr_pydantic.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# under the License.
1717

1818
import asyncio
19+
import warnings
1920
from typing import AsyncGenerator, Generator, List, Optional, Tuple
2021

2122
import pydantic
@@ -134,6 +135,14 @@ class MyModelWithConfig(pydantic.BaseModel):
134135
assert SubsetModel.model_config == {"arbitrary_types_allowed": True}
135136

136137

138+
def test_model_to_dict_no_deprecation_warning():
139+
model = OriginalModel(foo=1, bar="bar", nested=NestedModel(nested_field1=1))
140+
with warnings.catch_warnings():
141+
warnings.simplefilter("error")
142+
result = model_to_dict(model)
143+
assert "foo" in result
144+
145+
137146
def test_merge_to_state():
138147
model = OriginalModel(
139148
foo=1,

0 commit comments

Comments
 (0)