Sqlalchemy Footgun: Discarding the statement

This one has frustrated me for a while. It starts off with a REST API route. For example in fastAPI @app . get ( "/" ) def search_users ( session : Session ) -> list [ User ]: """Finds users optionally filter by user_id""" statement = select ( User ) . order_by ( User . name ) return session . execute ( statement ) . scalars () . all () Then we get asked …