- changed milestone to 1.2
- changed component to orm
- changed title to add a new AttributeEvent for the generic "flag_modified" event handler
- marked as enhancement
add a new AttributeEvent for the generic "flag_modified" event handler
Issue #3617
duplicate
(SQLAlchemy 1.0.11)
Column definition in model:
public_data = Column(MutableDict.as_mutable(JSON), nullable=False)
Event listener in same model file:
def __listener(target, value, oldvalue, initiator):
... do some stuff
event.listen(User.public_data, 'set', __listener)
Change that should trigger set
event:
# this doesn't work
user.public_data['address'] = ''
# but this works
user.public_data = {}
The event is never triggered when only a JSON attribute is modified. I stepped through the SQLAlchemy code and found that after the first line above is executed, the model's changed()
method is called, which I assume should be responsible for the event firing. Am I doing something wrong or is this not supported?
Comments (3)
-
repo owner -
repo owner - changed status to duplicate
Duplicate of
#3303. -
repo owner identical issue
- Log in to comment
the "set" event is only for normal attribute set events, it is not integrated into the sqlalchemy.ext.mutable extension. The mutable handler calls the "flag_modified" API feature of the attributes package which has no integration with the AttributeEvent suite at this time.
Pull requests (with at least some tests in test/orm/test_attributes and/or test/ext/test_mutable, both will be needed ultimately) are welcome in order to expedite the production of this new feature, thanks!