Bird
0
0

Identify the issue in this async Django view:

medium📝 Debug Q6 of 15
Django - Async Django
Identify the issue in this async Django view:
async def data_view(request):
    result = fetch_data()
    return JsonResponse({'data': result})

Assuming fetch_data() is a slow synchronous function.
ACalling a synchronous function without await blocks the async event loop
BMissing <code>async</code> keyword before <code>fetch_data()</code>
CJsonResponse cannot be used in async views
DThe view should return a string, not JsonResponse
Step-by-Step Solution
Solution:
  1. Step 1: Recognize sync call in async view

    Calling a blocking synchronous function inside an async view blocks the event loop.
  2. Step 2: Consequence

    This defeats the purpose of async and can degrade performance.
  3. Final Answer:

    Calling a synchronous function without await blocks the async event loop -> Option A
  4. Quick Check:

    Sync calls block async views unless run in thread [OK]
Quick Trick: Sync functions block async views unless awaited properly [OK]
Common Mistakes:
MISTAKES
  • Assuming all functions can be awaited
  • Thinking JsonResponse is incompatible with async views
  • Believing async keyword is needed before function calls

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes