-
Notifications
You must be signed in to change notification settings - Fork 574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attributes changed during event hook are not persisted #2007
Comments
Can you provide an actual reproducible test case? A gist is fine. |
Hi @ricardogama was trying to reproduce this bug in a clean environment and created this script which is very close to how the 'edit' works in Ghost model layer but with no luck. Looks like it's something internal that messes with Closing this issue as it seems like there's a problem on our side. Thanks for your time! |
Hey @ricardogama 👋 I have been working on an update to new bookshelf in Ghost again and finally was able to reproduce the scenario that causes the above issue. Here is a gist with bare minimum reproducible scenario - https://gist.github.com/gargol/c21f2069e176daaafe897718ce62c8fa. This line - https://gist.github.com/gargol/c21f2069e176daaafe897718ce62c8fa#file-bookself_bug_investigation-js-L28, is causing the My question regarding this behaviour is following: from bookshelf's perspective is it allowed to operate directly on P.S. Also spotted inconsistency related to this behaviour for insert scenario which is described here: https://gist.github.com/gargol/c21f2069e176daaafe897718ce62c8fa#file-bookself_bug_investigation-js-L77-L80 |
👋 |
Sorry, was meant to cc @ricardograca |
Good findings. I'd say it's not expected that users modify |
closes bookshelf#2007 - The attributes object can be modified within `triggerThen` through hooks. Sample scenario described here bookshelf#2007 (comment). - Recalculating 'attributesToSave' object in after-triggerThen step solves the syncronization issue because it is still based on model's `attributes` property (the reference is not lost)
Hey @ricardograca 👋 Thanks for quick reply! If the above fix is considered, would it be possible to ship it not just with the next planned version but also as a patch for |
Sure. I'll create a |
closes bookshelf#2007 - The attributes object can be modified within `triggerThen` through hooks. Sample scenario described here bookshelf#2007 (comment). - Recalculating 'attributesToSave' object in after-triggerThen step solves the syncronization issue because it is still based on model's `attributes` property (the reference is not lost)
closes #2007 - The attributes object can be modified within `triggerThen` through hooks. Sample scenario described here bookshelf/bookshelf#2007 (comment). - Recalculating 'attributesToSave' object in after-triggerThen step solves the syncronization issue because it is still based on model's `attributes` property (the reference is not lost)
closes #2007 - The attributes object can be modified within `triggerThen` through hooks. Sample scenario described here bookshelf/bookshelf#2007 (comment). - Recalculating 'attributesToSave' object in after-triggerThen step solves the syncronization issue because it is still based on model's `attributes` property (the reference is not lost)
Introduction
Changes made to object attributes during
saving
event hook are not persisted.Issue Description
When hooking into
saving
event of the object and making changes throughset('attrName', value)
during the hook, those changes are not later persisted in the database.The issue was spotted during version bump from 0.14.2 -> 0.15.1 in Ghost.
An example attribute change that is not being picked is one from this line.
When digging through the source code the main difference is that before this PR which introduced
attributesToSave
, attributes were taken fromthis.attributes
aftertriggerThen
was done with it's logic.Steps to reproduce issue
object.set('attrName', value)
Expected behaviour
When making changes to the saved object during even hooks they should be persisted.
Actual behaviour
The changes done during the
saving
event hook are not persisted.The text was updated successfully, but these errors were encountered: