This is an automated email from the ASF dual-hosted git repository.
skrawcz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/burr.git
The following commit(s) were added to refs/heads/main by this push:
new 8baae125 fix/#652 (#668) fixes pydantic warnings and minimum pins to
pydantic >=2.0
8baae125 is described below
commit 8baae125793db37736e463d36158b7520b2439b3
Author: Vaibhav Singh <[email protected]>
AuthorDate: Sat Apr 4 09:48:42 2026 +0530
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 <[email protected]>
---
burr/integrations/pydantic.py | 6 ++++--
pyproject.toml | 8 ++++----
tests/integrations/test_burr_pydantic.py | 9 +++++++++
3 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/burr/integrations/pydantic.py b/burr/integrations/pydantic.py
index dd1f95a5..300cbb6a 100644
--- a/burr/integrations/pydantic.py
+++ b/burr/integrations/pydantic.py
@@ -51,8 +51,10 @@ PydanticActionFunction = Callable[...,
Union[pydantic.BaseModel, Awaitable[pydan
def model_to_dict(model: pydantic.BaseModel, include: Optional[List[str]] =
None) -> dict:
"""Utility function to convert a pydantic model to a dictionary."""
- keys = model.model_fields.keys()
- keys = keys if include is None else [item for item in include if item in
model.model_fields]
+ keys = type(model).model_fields.keys()
+ keys = (
+ keys if include is None else [item for item in include if item in
type(model).model_fields]
+ )
return {key: getattr(model, key) for key in keys}
diff --git a/pyproject.toml b/pyproject.toml
index 346e41ce..70fb47e5 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -89,7 +89,7 @@ tests = [
"langchain_core",
"langchain_community",
"pandas",
- "pydantic[email]",
+ "pydantic[email]>=2.0",
"pyarrow",
"apache-burr[aiosqlite]",
"apache-burr[asyncpg]",
@@ -120,7 +120,7 @@ documentation = [
]
tracking-client = [
- "pydantic>1"
+ "pydantic>=2.0"
]
tracking-client-s3 = [
@@ -141,7 +141,7 @@ tracking-server = [
"click",
"fastapi",
"uvicorn",
- "pydantic",
+ "pydantic>=2.0",
"pydantic-settings",
"fastapi-pagination",
"fastapi-utils",
@@ -153,7 +153,7 @@ tracking-server = [
]
pydantic = [
- "pydantic"
+ "pydantic>=2.0"
]
haystack = [
diff --git a/tests/integrations/test_burr_pydantic.py
b/tests/integrations/test_burr_pydantic.py
index 8fbb94c0..567f8be6 100644
--- a/tests/integrations/test_burr_pydantic.py
+++ b/tests/integrations/test_burr_pydantic.py
@@ -16,6 +16,7 @@
# under the License.
import asyncio
+import warnings
from typing import AsyncGenerator, Generator, List, Optional, Tuple
import pydantic
@@ -134,6 +135,14 @@ def test_subset_model_copy_config():
assert SubsetModel.model_config == {"arbitrary_types_allowed": True}
+def test_model_to_dict_no_deprecation_warning():
+ model = OriginalModel(foo=1, bar="bar",
nested=NestedModel(nested_field1=1))
+ with warnings.catch_warnings():
+ warnings.simplefilter("error")
+ result = model_to_dict(model)
+ assert "foo" in result
+
+
def test_merge_to_state():
model = OriginalModel(
foo=1,