Skip to content

Relax pydantic, pydantic-settings, and uvicorn requirements #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 30, 2025
Merged
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: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ dependencies = [
"anyio>=4.5",
"httpx>=0.27",
"httpx-sse>=0.4",
"pydantic>=2.10.1,<3.0.0",
"pydantic>=2.7.2,<3.0.0",
"starlette>=0.27",
"sse-starlette>=1.6.1",
"pydantic-settings>=2.6.1",
"uvicorn>=0.30",
"pydantic-settings>=2.5.2",
"uvicorn>=0.23.1",
]

[project.optional-dependencies]
Expand Down
39 changes: 38 additions & 1 deletion tests/server/fastmcp/test_func_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,45 @@ async def check_call(args):


def test_complex_function_json_schema():
"""Test JSON schema generation for complex function arguments.

Note: Different versions of pydantic output slightly different
JSON Schema formats for model fields with defaults. The format changed in 2.9.0:

1. Before 2.9.0:
{
"allOf": [{"$ref": "#/$defs/Model"}],
"default": {}
}

2. Since 2.9.0:
{
"$ref": "#/$defs/Model",
"default": {}
}

Both formats are valid and functionally equivalent. This test accepts either format
to ensure compatibility across our supported pydantic versions.

This change in format does not affect runtime behavior since:
1. Both schemas validate the same way
2. The actual model classes and validation logic are unchanged
3. func_metadata uses model_validate/model_dump, not the schema directly
"""
meta = func_metadata(complex_arguments_fn)
assert meta.arg_model.model_json_schema() == {
actual_schema = meta.arg_model.model_json_schema()

# Create a copy of the actual schema to normalize
normalized_schema = actual_schema.copy()

# Normalize the my_model_a_with_default field to handle both pydantic formats
if 'allOf' in actual_schema['properties']['my_model_a_with_default']:
normalized_schema['properties']['my_model_a_with_default'] = {
'$ref': '#/$defs/SomeInputModelA',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems odd to me that you've relaxed down to 2.7.2, but in order to get this test passing you cast it to the "Pre-pydantic 2.7.2" version.

I suspect either your comment is wrong, or I'm misunderstanding something

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, the comment was wrong. I researched exactly when this change was made and updated the comment to reflect it.

The change happened in Pydantic 2.9.0. Here are the release notes for that change. You can see the PR here that made the change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To confirm that this works, I ran the test with pydantic 2.7.2 (the new version we are relaxing to) and 2.10.1 (the previously required lower bound) and confirmed the test passes with both.

'default': {}
}

assert normalized_schema == {
"$defs": {
"InnerModel": {
"properties": {"x": {"title": "X", "type": "integer"}},
Expand Down