node-orm-timestamps
node-orm-timestamps copied to clipboard
Bug in persist timestamps
Hi when i set persist to true orm-timestamp throws a "Maximum call stack size exceeded" error
Here is full stack trace and error:
(node:7632) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): RangeError: Maximum call stack size exceeded
(node:7632) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the
Node.js process with a non-zero exit code.
RangeError: Maximum call stack size exceeded
at Object.now (C:\actcustomer\node_modules\orm-timestamps\lib\orm-timestamps.js:7:16)
at Object.<anonymous> (C:\actcustomer\node_modules\orm-timestamps\lib\orm-timestamps.js:81:46)
at Object.exports.wait (C:\actcustomer\node_modules\orm\lib\Hook.js:19:26)
at saveInstanceProperty (C:\actcustomer\node_modules\orm\lib\Instance.js:422:10)
at Object.set [as modified_at] (C:\actcustomer\node_modules\orm\lib\Instance.js:521:11)
at Object.<anonymous> (C:\actcustomer\node_modules\orm-timestamps\lib\orm-timestamps.js:81:36)
at Object.exports.wait (C:\actcustomer\node_modules\orm\lib\Hook.js:19:26)
at saveInstanceProperty (C:\actcustomer\node_modules\orm\lib\Instance.js:422:10)
at Object.set [as modified_at] (C:\actcustomer\node_modules\orm\lib\Instance.js:521:11)
at Object.<anonymous> (C:\actcustomer\node_modules\orm-timestamps\lib\orm-timestamps.js:81:36)
at Object.exports.wait (C:\actcustomer\node_modules\orm\lib\Hook.js:19:26)
at saveInstanceProperty (C:\actcustomer\node_modules\orm\lib\Instance.js:422:10)
at Object.set [as modified_at] (C:\actcustomer\node_modules\orm\lib\Instance.js:521:11)
at Object.<anonymous> (C:\actcustomer\node_modules\orm-timestamps\lib\orm-timestamps.js:81:36)
at Object.exports.wait (C:\actcustomer\node_modules\orm\lib\Hook.js:19:26)
at saveInstanceProperty (C:\actcustomer\node_modules\orm\lib\Instance.js:422:10)
Maximum call stack size exceeded
Hi @Eddie-CooRo, I'm afraid I haven't seen this before, however it looks like the issue stems from you having autoSave
enabled on your object. This means that as soon as this plugin changes the modified_at
field, orm
's Instance attempts to save the new changes - this obviously continues ad-infinitum until you end up with a stack overflow.
I, unfortunately, can't see a way to make a plugin like this work with autoSave
enabled so my advice is going to be to either disable autoSave
and manually trigger saving of your instances (which is likely going to reduce the number of queries you make to the DB anyway) or manually manage the modified_at
timestamp.
Sorry I can't be of more help
Thank you so much I didn't know that it's because of autosave... I'll look for a workaround