Skip to content

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

@biellSilva

Description

@biellSilva

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedContributions especially welcomeruleImplementing or modifying a lint ruletype-inferenceRequires more advanced type inference.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions