Bird
0
0

What is wrong with this FastAPI app code that attempts to add a global dependency?

medium📝 Debug Q6 of 15
FastAPI - Dependency Injection
What is wrong with this FastAPI app code that attempts to add a global dependency?
from fastapi import FastAPI, Depends

def check_auth():
    pass

app = FastAPI(dependencies=Depends(check_auth))
AThe check_auth function must return a value
BThe dependencies parameter expects a list, not a single Depends instance
CDepends cannot be used with functions without parameters
DGlobal dependencies must be added with @app.dependency decorator
Step-by-Step Solution
Solution:
  1. Step 1: Check dependencies parameter type

    The dependencies parameter requires a list of Depends instances, not a single Depends object.
  2. Step 2: Analyze the code

    Here, dependencies=Depends(check_auth) passes a single Depends instance instead of a list.
  3. Step 3: Confirm other options

    check_auth does not need to return a value, Depends works with parameterless functions, and no such decorator exists.
  4. Final Answer:

    The dependencies parameter expects a list, not a single Depends instance -> Option B
  5. Quick Check:

    dependencies must be a list [OK]
Quick Trick: dependencies parameter requires a list of Depends [OK]
Common Mistakes:
MISTAKES
  • Passing a single Depends instead of a list
  • Assuming dependency functions must return values
  • Believing a special decorator is needed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FastAPI Quizzes