question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MapperEvents before_update, after_update do not work

See original GitHub issue

Migrated 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:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

3reactions
sqlalchemy-botcommented, Nov 27, 2018

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

The MapperEvents.before_update() and MapperEvents.after_update() events are not invoked from this method. Instead, the SessionEvents.after_bulk_update() method is provided to act upon a mass UPDATE of entity rows.

hope this helps!

0reactions
sqlalchemy-botcommented, Nov 27, 2018

Changes by Michael Bayer (@zzzeek):

  • changed status to closed
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found