Introduce custom checker for unsafe dependency resolution
What does this merge request do and why?
This MR introduces a custom lint rule to prevent developers from using Depends(Provide[...])
.
See fix: FastAPI runs new threads for dependency re... (!606 - merged) for more information.
Here is an example of lint job failure: https://gitlab.com/gitlab-org/modelops/applied-ml/code-suggestions/ai-assist/-/jobs/5997255178
Here is an example of output:
Code:
async def chat(
request: Request,
chat_request: ChatRequest,
anthropic_claude_factory: Factory[AnthropicModel] = Depends(
Provide[ContainerApplication.chat.anthropic_claude_factory.provider]
),
):
Lint:
(ai-gateway-py3.10) shinya@shinya-XPS-15-9530:~/ai-assist$ make lint
Installing lint dependencies...
Installing dependencies from lock file
No dependencies to install or update
Installing the current project: ai_gateway (0.1.0)
Running flake8...
Running black check...
All done! ✨ 🍰 ✨
151 files would be left unchanged.
Running isort check...
Skipped 1 files
Running pylint check...
************* Module ai_gateway.api.v1.chat.agent
ai_gateway/api/v1/chat/agent.py:43:56: W5001: Unsafe Dependency Resolution Detected (unsafe-dependency-resolution)
make: *** [Makefile:73: check-pylint] Error 4
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
Merge request checklist
-
Tests added for new functionality. If not, please raise an issue to follow up. -
Documentation added/updated, if needed.
Edited by Shinya Maeda