Change8

0.137.0

Breaking Changes
📦 fastapiView on GitHub →
2 breaking5 features🔧 2 symbols

Summary

This release refactors the internal handling of `APIRouter` inclusion to preserve route instances instead of cloning them, enabling new features like adding routes after inclusion. This change modifies the structure of `router.routes`, which is a breaking change for code relying on its previous list structure.

⚠️ Breaking Changes

  • The structure of `router.routes` has changed from a plain list of `APIRoute` objects to potentially containing intermediate metadata objects that form a tree structure when routers are included. Any logic that iterated directly over `router.routes` expecting only `APIRoute` objects or modifying them will be affected and must be updated to handle the new tree structure or use appropriate methods to access the final routes.
  • Logic that relied on iterating on `router.routes` directly to extract data will fail or yield incomplete results because it will encounter new internal objects instead of just `APIRoute` instances.

Migration Steps

  1. Review any code that iterates over or modifies `router.routes` directly and adapt it to handle the new tree structure or use alternative methods to access the final route definitions.

✨ New Features

  • Internal refactoring preserves `APIRouter` and `APIRoute` instances when including routers, meaning routes are no longer cloned.
  • Adding routes (path operations) after a router is included now works correctly and is reflected immediately.
  • Including a subrouter before adding routes to it now works because the entire router object is stored instead of copying its routes.
  • Potential memory savings due to routes not being copied during router inclusion.
  • Experimental alpha features enabled by preserved instances: `APIRouter` now has `.matches()` and `.handle()` methods, allowing routers to customize request matching and handling (e.g., versioning via headers). These are undocumented and subject to change.

Affected Symbols