On Dec 1, 2011, at 7:24 PM, Łukasz Czuja wrote:

> Hi,
> 
> I do not see anywhere in the docs a way to pass custom attributes to
> event listeners:
> 
> event.listen(cls, 'before_insert', before_insert_listener, arg1, arg2,
> kwarg1 = 'value', kwarg2 = 'value2')
> 
> so that the before_insert_listener can have mixed signature:
> 
> def before_insert_listener(mapper, connection, target, arg1, *args,
> **kwargs):
> 
> the only other solution would be to store extra processing information
> on the 'target' itself.
> 
> Should be reasonable if there is not another way to pass around
> arguments. Should I open a ticket then?

this kind of pollutes the API with kwargs that might be needed for the listen() 
function itself someday, these are external use cases that are easily handled 
in Python:

def before_insert_listener(arg1, arg2, k1='value', k2='value'):
        def before_insert(mapper, conn, target):
                ... body
        return before_insert

event.listen(cls, 'before_insert', before_insert_listener(arg1, arg2, k1='x', 
k2='y'))


-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to