astral-sh/ruff

`FAST003` false positive when path parameter is included inside a `BaseModel` dependency

Open

#17226 opened on Apr 5, 2025

View on GitHub
 (3 comments) (0 reactions) (0 assignees)Rust (47,527 stars) (2,088 forks)batch import
help wantedruletype-inference

Description

Summary

I’ve noticed that the rule FAST003 (fast-api-unused-path-parameter) is reporting false positives when the path parameter is provided via a BaseModel using Depends.

For example, consider the following code:

from fastapi import APIRouter, Depends
from pydantic import BaseModel
from typing import Annotated

router = APIRouter()

class MyParams(BaseModel):
    my_id: int

@router.get("/{my_id}")
async def get_id(params: Annotated[MyParams, Depends()]):
    return {"my_id": params.my_id}

In this case, my_id is being used correctly via the params dependency, but the linter still raises: Parameter my_id appears in route path, but not in get_id signature Ruff [FAST003]

However, this is a valid and common FastAPI pattern, where parameters are parsed from Depends() into a Pydantic model.

Expected behavior

No warning should be raised when the path parameter is being handled inside a BaseModel via dependency injection.

Actual behavior

The linter raises FAST003 even though the parameter is properly used.

Additional notes

  • This pattern is especially useful for grouping parameters together.
  • The rule might need to inspect Depends() models to detect path parameters coming from annotated dependencies.

Versions

Ruff: 0.11.3 FastAPI: 0.115.12 Pydantic: 2.11.2

Version

0.11.3

Contributor guide