New: Cookbooks and AI ExplanationsStep-by-Step recipes to solve problems connected to Roadmaps and Cheat Sheets. Need more details? Use AI buttons for structured and simple explanations with concrete examples throughout the whole platform.Take a look
My API returns a 500 the moment it tries to read a relationship, but only sometimes, and the trace points at code that never touches the database.
What you'll have at the end
An endpoint that loads every relationship before the session closes, with no more DetachedInstanceError crashes on repeated calls
You need
A route that already queries an object through a session-per-request pattern and serializes it into a response model naming one of that object's relationships.
Not covered
Handing this same object to a background task or a second thread after the request ends; that needs its own fresh session opened after the request is gone.
Checked 18 Aug 2026
Part of the ORM and Database Abstraction Tools cookbook