Bird
0
0

You have a Flask-SQLAlchemy relationship defined as lazy='joined', but your application still issues multiple queries when accessing related data. What is the most likely cause?

medium📝 Debug Q6 of 15
Flask - Performance Optimization
You have a Flask-SQLAlchemy relationship defined as lazy='joined', but your application still issues multiple queries when accessing related data. What is the most likely cause?
AThe relationship is not properly configured with back_populates.
BYou are accessing the related data before the parent query.
CThe query does not use <code>options(joinedload())</code> to enforce eager loading.
DYou forgot to import the related model.
Step-by-Step Solution
Solution:
  1. Step 1: Understand eager loading enforcement

    Even if lazy='joined' is set, the query must use options(joinedload()) to eagerly load related data.
  2. Step 2: Identify cause of multiple queries

    Without joinedload(), SQLAlchemy may still issue separate queries despite lazy='joined'.
  3. Final Answer:

    The query does not use options(joinedload()) to enforce eager loading. -> Option C
  4. Quick Check:

    Eager loading requires joinedload() in query [OK]
Quick Trick: Use options(joinedload()) to enforce eager loading [OK]
Common Mistakes:
MISTAKES
  • Assuming lazy='joined' alone enforces eager loading
  • Ignoring query options
  • Misconfiguring back_populates

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes