While trying to refactor a Flask PeeWee query written using raw SQL that needed to be done using standard PeeWee methods I was struggling to understand why they query structure I had used was returning zero rows compared to the SQL equivalent.
I struggled equally to understand if there was any way to determine if there were any PeeWee methods that could be applied to a query to retrieve the underlying SQL when I came across the following:
# Print all queries to stderr. import logging logger = logging.getLogger('peewee') logger.addHandler(logging.StreamHandler()) logger.setLevel(logging.DEBUG)
Restart the application and all the queries are shown on stderr along with the placeholder values.
The suggestion above was founmd at https://stackoverflow.com/questions/45456415/peewee-to-print-generated-queries