> -----Original Message----- > From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com] > On Behalf Of bool > Sent: 15 April 2011 14:41 > To: sqlalchemy > Subject: [sqlalchemy] Re: Context based execution > > Hi, > > Thanks a lot. Can someone answer this question also > > ===================================================== > >> @compiles(Select) > >> def contextual_select_thing(select, compiler, **kw): > > This method gets registered with Select. But How/When does this > registration automatically happen? > ==================================================== >
The implementation of the compiler extension is very short - you can see it at http://www.sqlalchemy.org/trac/browser/lib/sqlalchemy/ext/compiler.py. It looks like it modifies the target class to add _compiler_dispatcher and _compiler_dispatch attributes to it (or update them if it already has them). The SA statement compiler must look at these attributes to determine how to compile the statement. The registration happens as soon as the @compiles(Select) decorator is evaluated. If it is at module-global scope (rather than being buried inside another function), it'll happen when the module is imported. Hope that helps, Simon -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.