listening for events on 'mapper'

11 views
Skip to first unread message

Tim Tisdall

unread,
Apr 8, 2015, 5:14:15 PM4/8/15
to sqlal...@googlegroups.com
I have some code I'm trying to figure out...  Here it is:

from sqlalchemy import event
from colanderalchemy import setup_schema
from sqlalchemy.orm import mapper

event.listen(mapper, 'mapper_configured', setup_schema)


It appears to call `setup_schema` on every ORM class that derives from the `declarative_base()`.  All the documentation in SQLAlchemy shows event.listen being called on specific classes or mappers and I'm wondering if this usage is a documented feature.

Mike Bayer

unread,
Apr 8, 2015, 5:27:50 PM4/8/15
to sqlal...@googlegroups.com


On 4/8/15 5:14 PM, Tim Tisdall wrote:
I have some code I'm trying to figure out...  Here it is:

from sqlalchemy import event
from colanderalchemy import setup_schema
from sqlalchemy.orm import mapper

event.listen(mapper, 'mapper_configured', setup_schema)


It appears to call `setup_schema` on every ORM class that derives from the `declarative_base()`.  All the documentation in SQLAlchemy shows event.listen being called on specific classes or mappers and I'm wondering if this usage is a documented feature.

yes, mapper events can be passed the "mapper" function itself which is recognized as one way to assign an event to all mappers.
that would qualify as "documented" :)   The formatting is cleaner in http://docs.sqlalchemy.org/en/latest/orm/events.html#sqlalchemy.orm.events.MapperEvents.



--
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+...@googlegroups.com.
To post to this group, send email to sqlal...@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Tim Tisdall

unread,
Apr 8, 2015, 6:29:50 PM4/8/15
to sqlal...@googlegroups.com
Sorry, I just saw the "the Mapper class itself and the mapper()
function indicate listening for all mappers." on the latest docs.
Thanks.
> You received this message because you are subscribed to a topic in the
> Google Groups "sqlalchemy" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/sqlalchemy/bmWUxihSDqY/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
Reply all
Reply to author
Forward
0 new messages