Bird
0
0

What is wrong with this async middleware implementation?

medium📝 Debug Q7 of 15
Django - Async Django
What is wrong with this async middleware implementation? class AsyncMiddleware: def __init__(self, get_response): self.get_response = get_response def __call__(self, request): response = await self.get_response(request) return response
A__init__ method is missing async keyword
B__call__ is not async but uses await inside
Cget_response should not be awaited
DMiddleware must not define __call__
Step-by-Step Solution
Solution:
  1. Step 1: Check __call__ method declaration

    Using await inside a function requires it to be async.
  2. Step 2: Identify mismatch

    Here, __call__ is sync but uses await, causing syntax error.
  3. Final Answer:

    __call__ is not async but uses await inside -> Option B
  4. Quick Check:

    Await requires async function declaration [OK]
Quick Trick: Await only inside async functions [OK]
Common Mistakes:
MISTAKES
  • Defining sync __call__ with await
  • Thinking __init__ needs async
  • Believing get_response can't be awaited

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes