Ctrl K
Python · Mid-level · Theory

In a SQLAlchemy application, a function returns an object from a repository, and accessing one of its related fields throws DetachedInstanceError. Why does this happen, and how should you organize session handling properly?

~4 min by voice

How to approach it

This checks whether you understand the lifecycle of an ORM object in SQLAlchemy: the object's tie to the session, lazy loading as a hidden SQL query, and the ability to set session boundaries and a relationship loading strategy properly.

Have you seen this question in a real interview?
Answers0
Avg. score—
Strong—
Practiced0
Topics
Similar questionsDesign how a high-load Python service using SQLAlchemy works with PostgreSQL: dozens of instances, each with several workers. How would you organize the connection pools and the session lifecycle? SeniorThe orders list page has started taking several seconds to load, and in the logs you see hundreds of near-identical SQL queries per HTTP request. What's going on, and how would you fix it? Mid-levelWhat is the N+1 query problem in an ORM, and how do you solve it in Django? JuniorThe order list page in the Django admin takes ten seconds to load, and the logs show hundreds of SQL queries per page load. What's going on, and how do you fix it? Mid-levelTell me about the N+1 query problem in the Django ORM. How do you find it, and which ORM tools do you use to fix it? Senior

Answer by voice

The interviewer will ask this question and listen. Think out loud and ask for a hint if you need one. When you're done, pause or tap “That's my answer”. In about a minute, your score and the points you covered show up here.

Sign in to answer

Best with headphones · ~4 min