Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions burr/integrations/pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}


Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ tests = [
"langchain_core",
"langchain_community",
"pandas",
"pydantic[email]",
"pydantic[email]>=2.0",
"pyarrow",
"apache-burr[aiosqlite]",
"apache-burr[asyncpg]",
Expand Down Expand Up @@ -120,7 +120,7 @@ documentation = [
]

tracking-client = [
"pydantic>1"
"pydantic>=2.0"
]

tracking-client-s3 = [
Expand All @@ -141,7 +141,7 @@ tracking-server = [
"click",
"fastapi",
"uvicorn",
"pydantic",
"pydantic>=2.0",
"pydantic-settings",
"fastapi-pagination",
"fastapi-utils",
Expand All @@ -153,7 +153,7 @@ tracking-server = [
]

pydantic = [
"pydantic"
"pydantic>=2.0"
]

haystack = [
Expand Down
9 changes: 9 additions & 0 deletions tests/integrations/test_burr_pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# under the License.

import asyncio
import warnings
from typing import AsyncGenerator, Generator, List, Optional, Tuple

import pydantic
Expand Down Expand Up @@ -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,
Expand Down