Hello I'd like to understand how to turn off a before_compile listener (e.g. soft delete, to include deleted items).
For example, I've adapted the example from the docs: https://docs.sqlalchemy.org/en/13/orm/events.html?highlight=before_compile#sqlalchemy.orm.events.QueryEvents.before_compile <https://docs.sqlalchemy.org/en/13/orm/events.html?highlight=before_compile#sqlalchemy.orm.events.QueryEvents.before_compile> To use the field 'archived' , which works as expected. @event.listens_for(Query, "before_compile", retval=True, bake_ok=True) def filter_archived(query): for desc in query.column_descriptions: if desc["type"] is Person: entity = desc["entity"] query = query.filter(entity.archived == 0) return query I've tried things such as: Person.query.filter_by(archived=True).all() But I don't understand yet where I should put such kwargs to override the before_compile events listener Is the following the right path? @event.listens_for(Query, "before_compile", retval=True, bake_ok=True) def filter_archived(query, **kwargs): for desc in query.column_descriptions: if kwargs["include_archived"] is not True and desc["type"] is Person: entity = desc["entity"] query = query.filter(entity.archived == 0) return query Kind regards Chris -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/d9ca992a-9075-4c1b-b4a0-32179f48b5bdn%40googlegroups.com.