fastapi - 💡(How to fix) Fix Review: compatibility and contract risks around Pydantic >=2.9.0 floor bump [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
fastapi/fastapi#15236Fetched 2026-04-08 01:40:17
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Author
Participants
Timeline (top)
converted_to_discussion ×1locked ×1

I reviewed the most recent framework-affecting upstream changes visible around FastAPI 0.135.2. The main substantive change in the inspected window is PR #15139:

  • Increase lower bound to pydantic >= 2.9.0
  • Adjust tests to accept multiple schema shapes across Pydantic 2.9/2.10/2.11

Overall, the code delta is small, but the compatibility impact is not. The main concern is release-management and contract clarity, not request-path performance.

Root Cause

I reviewed the most recent framework-affecting upstream changes visible around FastAPI 0.135.2. The main substantive change in the inspected window is PR #15139:

  • Increase lower bound to pydantic >= 2.9.0
  • Adjust tests to accept multiple schema shapes across Pydantic 2.9/2.10/2.11

Overall, the code delta is small, but the compatibility impact is not. The main concern is release-management and contract clarity, not request-path performance.

Fix Action

Fix / Workaround

High — Potential breaking change shipped as a patch release

FastAPI changed its dependency floor from pydantic>=2.7.0 to pydantic>=2.9.0 in what appears as a patch release (0.135.2).

Why this matters

  • Patch upgrades are commonly assumed to be safe.
  • This can break downstream environments pinned to Pydantic 2.7.x or 2.8.x.
  • Lockfile resolution may now force broader upgrades than users expect.
RAW_BUFFERClick to expand / collapse

Summary

I reviewed the most recent framework-affecting upstream changes visible around FastAPI 0.135.2. The main substantive change in the inspected window is PR #15139:

  • Increase lower bound to pydantic >= 2.9.0
  • Adjust tests to accept multiple schema shapes across Pydantic 2.9/2.10/2.11

Overall, the code delta is small, but the compatibility impact is not. The main concern is release-management and contract clarity, not request-path performance.

Findings

High — Potential breaking change shipped as a patch release

FastAPI changed its dependency floor from pydantic>=2.7.0 to pydantic>=2.9.0 in what appears as a patch release (0.135.2).

Why this matters

  • Patch upgrades are commonly assumed to be safe.
  • This can break downstream environments pinned to Pydantic 2.7.x or 2.8.x.
  • Lockfile resolution may now force broader upgrades than users expect.

Recommendation

  • Treat this as a breaking compatibility note in release notes, or
  • Move dependency floor changes like this to a minor release unless there is a hard runtime correctness reason.

Medium — Test contract is now more permissive, reducing schema-surface precision

The updated tests use flexible assertions (IsOneOf) to accept multiple OpenAPI/JSON Schema shapes depending on the installed Pydantic version.

Examples include:

  • top-level schema presence/absence differences
  • additionalProperties presence differences
  • const-only vs const + enum output differences

Why this matters Generated schema is part of FastAPI's effective public contract. More permissive tests reduce spurious failures, but they also make it easier for accidental schema drift to pass unnoticed.

Recommendation

  • Keep compatibility tests flexible where needed.
  • Add invariant tests for FastAPI-owned guarantees, e.g. discriminator behavior, required fields, ref stability, and documented normalization behavior.

Medium — Version-floor bump appears driven by compatibility/test variance more than visible runtime framework changes

In the inspected diff, the substantive changes are dependency metadata and tests. I did not find corresponding FastAPI runtime implementation changes in fastapi/ explaining why >=2.9.0 is strictly required.

Why this matters If older supported Pydantic v2 versions still work at runtime, narrowing the support range increases upgrade friction without clear user benefit.

Recommendation

  • Document the exact runtime reason >=2.9.0 is required.
  • If the issue is mainly schema-output variance in tests, prefer encoding that in tests rather than constraining all downstream users.

Low — No notable FastAPI-side performance risk in the inspected change

The recent diff does not introduce meaningful new work in request handling, dependency injection, routing, or serialization.

Assessment

  • No obvious FastAPI runtime performance regression.
  • Any performance effect would likely come indirectly from Pydantic version behavior, not new FastAPI logic.

Low — Public API design patterns appear stable in the inspected window

I did not see new framework abstractions or public API design changes in the recent window. Impact is mostly packaging/schema compatibility, not endpoint ergonomics.

Suggested follow-ups

  1. Explicitly call out the Pydantic minimum-version bump as a compatibility-impacting change.
  2. Re-evaluate whether the lower bound truly must be 2.9.0 for runtime correctness.
  3. Split tests into:
    • version-tolerant compatibility assertions
    • strict FastAPI invariants
  4. If newer Pydantic versions are required for correctness or performance, document that rationale directly in the PR/release notes.

Bottom line

This change set looks mechanically safe, but semantically it has a meaningful compatibility smell: a patch release tightening a core dependency floor is something users may reasonably experience as a breaking change.

extent analysis

Fix Plan

To address the compatibility issues introduced by the recent FastAPI update, follow these steps:

  1. Update Pydantic version: If you're using a version of Pydantic older than 2.9.0, update it to at least 2.9.0 to ensure compatibility with FastAPI 0.135.2.
  2. Review and update dependencies: Check your project's dependencies and update them if necessary to ensure they are compatible with the new Pydantic version.
  3. Split tests: Separate tests into two categories:
    • Version-tolerant compatibility assertions using IsOneOf to accommodate different Pydantic versions.
    • Strict FastAPI invariants to ensure consistency across different Pydantic versions.

Example code for version-tolerant tests:

from pydantic import BaseModel
from fastapi import FastAPI
from fastapi.testclient import TestClient

app = FastAPI()

class User(BaseModel):
    id: int
    name: str

@app.get("/users/")
def read_users():
    return [{"id": 1, "name": "John"}]

client = TestClient(app)

def test_read_users():
    response = client.get("/users/")
    assert response.status_code == 200
    assert response.json() == [{"id": 1, "name": "John"}]

Example code for strict FastAPI invariants:

from fastapi import FastAPI
from fastapi.testclient import TestClient

app = FastAPI()

@app.get("/users/")
def read_users():
    return [{"id": 1, "name": "John"}]

client = TestClient(app)

def test_read_users_invariant():
    response = client.get("/users/")
    assert response.status_code == 200
    assert len(response.json()) == 1
    assert "id" in response.json()[0]
    assert "name" in response.json()[0]

Verification

To verify that the fix worked:

  1. Run your tests with different Pydantic versions to ensure compatibility.
  2. Check your project's dependencies to ensure they are up-to-date and compatible with the new Pydantic version.
  3. Review your API's behavior to ensure it remains consistent across different Pydantic versions.

Extra Tips

  • Document the rationale behind the Pydantic version bump in your project's release notes.
  • Consider adding tests to ensure that your API's behavior remains consistent across different Pydantic versions.
  • Keep your dependencies up-to-date to ensure compatibility with the latest FastAPI and Pydantic versions.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING