From 8baae125793db37736e463d36158b7520b2439b3 Mon Sep 17 00:00:00 2001 From: Vaibhav Singh <95634443+vbhavh@users.noreply.github.com> Date: Sat, 4 Apr 2026 09:48:42 +0530 Subject: [PATCH] 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 --- 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 dd1f95a58..300cbb6a0 100644 --- a/burr/integrations/pydantic.py +++ b/burr/integrations/pydantic.py @@ -51,8 +51,10 @@ 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 346e41ce8..70fb47e51 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 8fbb94c02..567f8be65 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 @@ class MyModelWithConfig(pydantic.BaseModel): 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,