Use event hook immediately after defining your engine:
from sqlalchemy import event def disable_query_cache(conn, record): conn.cursor().execute("SET SESSION query_cache_type = OFF") # this is probably in your Pyramid setup code engine = create_engine(...) if DEBUGGING: event.listen(engine, 'connect', disable_query_cache)
You can do this globally by adding a hook to the Pool class, but (a) you probably want the Pyramid settings to be available anyway, so you can decide whether to add or not a hook, and (b) a global state )
source share