I have now rewritten two projects to use the PyPika query builder (https://pypika.readthedocs.io/) instead of an object-relational mapper, and the query builder approach had many fewer WTF moments. Caveat: they are small projects with relatively simple data models (a dozen to a couple of dozen tables, no need for recursive queries) and I haven't had to maintain the code through schema changes yet.