[Sqlalchemy-tickets] Issue #4263: MapperEvents before_update, after_update do not work (zzzeek/sqla
Brought to you by:
zzzeek
From: Karol N. <iss...@bi...> - 2018-05-21 13:46:41
|
New issue 4263: MapperEvents before_update, after_update do not work https://bitbucket.org/zzzeek/sqlalchemy/issues/4263/mapperevents-before_update-after_update-do 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. ``` #!python 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" ``` |