On Thu, Dec 13, 2018 at 2:59 PM Daniel Leon <[email protected]> wrote:
>
> I know that you can define an on set event handler for an attribute using the 
> decorator @event.listens_for(Class.Attribute, 'set'). I'd like a single event 
> handler to handle every attribute on every class. How can I do this?
>
> In the event handler I want to refresh the object before setting the value 
> and commit after. I know this is strange, but I'm converting a project from 
> SQLObject and to make the conversion as seamless as possible I want to make 
> SQLAlchemy mimic SQLObject's behaviour.

the attribute event handlers don't have a "global" hook like this, so
there is a recipe at
https://docs.sqlalchemy.org/en/latest/_modules/examples/custom_attributes/listen_for_events.html
where another event, "attribute_instrument", is used to intercept
where an ORM attribute is set up, so then you can apply listeners to
it.



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

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

Reply via email to