mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-20 05:43:55 +00:00
core[patch]: check for model_fields attribute (#25108)
`__fields__` raises a warning in pydantic v2
This commit is contained in:
parent
6e9a8b188f
commit
803eba3163
@ -1666,7 +1666,10 @@ def _get_all_basemodel_annotations(
|
|||||||
for name, param in inspect.signature(cls).parameters.items():
|
for name, param in inspect.signature(cls).parameters.items():
|
||||||
# Exclude hidden init args added by pydantic Config. For example if
|
# Exclude hidden init args added by pydantic Config. For example if
|
||||||
# BaseModel(extra="allow") then "extra_data" will part of init sig.
|
# BaseModel(extra="allow") then "extra_data" will part of init sig.
|
||||||
if (fields := getattr(cls, "__fields__", {})) and name not in fields:
|
if (
|
||||||
|
fields := getattr(cls, "model_fields", {}) # pydantic v2+
|
||||||
|
or getattr(cls, "__fields__", {}) # pydantic v1
|
||||||
|
) and name not in fields:
|
||||||
continue
|
continue
|
||||||
annotations[name] = param.annotation
|
annotations[name] = param.annotation
|
||||||
orig_bases: Tuple = getattr(cls, "__orig_bases__", tuple())
|
orig_bases: Tuple = getattr(cls, "__orig_bases__", tuple())
|
||||||
|
@ -1746,6 +1746,7 @@ def test__is_message_content_type(obj: Any, expected: bool) -> None:
|
|||||||
|
|
||||||
@pytest.mark.skipif(PYDANTIC_MAJOR_VERSION != 2, reason="Testing pydantic v2.")
|
@pytest.mark.skipif(PYDANTIC_MAJOR_VERSION != 2, reason="Testing pydantic v2.")
|
||||||
@pytest.mark.parametrize("use_v1_namespace", [True, False])
|
@pytest.mark.parametrize("use_v1_namespace", [True, False])
|
||||||
|
@pytest.mark.filterwarnings("error")
|
||||||
def test__get_all_basemodel_annotations_v2(use_v1_namespace: bool) -> None:
|
def test__get_all_basemodel_annotations_v2(use_v1_namespace: bool) -> None:
|
||||||
A = TypeVar("A")
|
A = TypeVar("A")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user