python runtime_error ai_generated true

fastapi.exceptions.FastAPIError: Dependency overrides are not supported for this dependency.

ID: python/fastapi-dependency-override

Also available as: JSON · Markdown · 中文
80%Fix Rate
87%Confidence
0Evidence
2025-05-25First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
0.100.x active
0.110.x active

Root Cause

Attempting to override a dependency that is not a function or callable, or using incorrect override syntax.

generic

中文

尝试覆盖不是函数或可调用的依赖项,或使用了错误的覆盖语法。

Workarounds

  1. 95% success
    def get_db():
        return 'real'
    app.dependency_overrides[get_db] = lambda: 'fake'
  2. 85% success
    class Dep:
        def __call__(self):
            return 'real'
    app.dependency_overrides[Dep()] = lambda: 'fake'

Dead Ends

Common approaches that don't work:

  1. 60% fail

    If dep is not a function, this fails.

  2. 80% fail

    Fragile and not recommended.