MapperEvents before_update, after_update do not work
See original GitHub issueMigrated issue, originally created by Karol Narowski
Function is not called when set in listener. before_insert and after_insert is working well but before_update and after_update are not called. Ex.
class User(Base):
__tablename__ = 'users'
uid = Column(String(36), primary_key=True, unique=True, default=generate_uuid)
name = Column(String(15), nullable=False)
description = Column(String(25), nullable=False)
phone = Column(String(20), nullable=False)
hash = Column(String(128), nullable=True, unique=True)
created_on = Column(DateTime(), default=datetime.utcnow)
updated_on = Column(DateTime(), default=datetime.utcnow, onupdate=datetime.utcnow)
@listens_for(User, 'before_insert')
def before_insert_function(mapper, connection, target):
print(target.phone)
target.hash = "OtherInsert"
@listens_for(User, 'before_update')
def before_update_function(mapper, connection, target):
print(target.uid)
print(target.phone)
target.hash = "OtherUpdate"
Issue Analytics
- State:
- Created 5 years ago
- Comments:6
Top Results From Across the Web
ORM Events - SQLAlchemy 1.4 Documentation
The listen() function will accept Session objects as well as the return ... This means that an instance being sent to MapperEvents.after_update() is...
Read more >vba - Unable to capture AfterUpdate event with a custom event ...
As you note, the Enter, Exit, BeforeUpdate and AfterUpdate events aren't available to variables ... This does not work, and creates a run...
Read more >Form.BeforeUpdate event (Access) - Microsoft Learn
BeforeUpdate macros and event procedures run only if you change the data in a control. This event does not occur when a value...
Read more >Events - Atlas Database Framework for PHP
These mapper-level events are called in addition to the various table-level events. ... extends MapperEvents { public function beforeUpdate(Mapper $mapper, ...
Read more >Deprecated ORM Event Interfaces - 《SQLAlchemy 1.3 ...
Mapper Events · afterinsert (_mapper, connection, instance) · Receive an object instance after that instance is inserted.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Michael Bayer (@zzzeek) wrote:
yes! the query.update() and query.delete() methods don’t interact with the mapper before_update/after_update/before_delete/after/delete events.
http://docs.sqlalchemy.org/en/latest/orm/query.html?highlight=query update#sqlalchemy.orm.query.Query.update
hope this helps!
Changes by Michael Bayer (@zzzeek):