python type_error ai_generated true

TypeError: 'function' object is not callable in path operation

ID: python/fastapi-typeerror-path-operation-not-callable

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
0Evidence
2024-06-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

A decorator is used without parentheses, e.g., @app.get instead of @app.get().

generic

中文

装饰器使用时不带括号,例如 @app.get 而不是 @app.get()。

Workarounds

  1. 95% success Use decorator with parentheses and path
    @app.get('/items')
    async def get_items():
        return []
  2. 90% success Check for missing parentheses in custom decorators
    def my_decorator(func):
        return func
    # Use: @my_decorator
    def my_func(): pass

Dead Ends

Common approaches that don't work:

  1. Adding parentheses but not passing path 60% fail

    Still missing required argument.

  2. Using class-based view incorrectly 50% fail

    May conflict with function-based approach.