hexojs / hexojs/warehouse

Potential mistake prevents model data modification in pre-save hooks

Open
#109 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
206
Forks
22
PR merge metrics
No merged PRs in 30d

Description

Please consider this piece of `model.js` source:
https://github.com/hexojs/warehouse/blob/067dd5395d6eff3053606fdd8794c5c90d96b022/lib/model.js#L161-L164

It can be seen, that `pre save` hook is received `data` variable and receives (potentially modified) `data` in `then()` (at the line 161), but **ignores** this information and inserts previously defined `result` variable instead at the line 163.

It effectively results into lack of ability to perform any `data` modifications in `pre save` hooks.

Same approach is used for [updating](https://github.com/hexojs/warehouse/blob/067dd5395d6eff3053606fdd8794c5c90d96b022/lib/model.js#L253) and [replacement](https://github.com/hexojs/warehouse/blob/067dd5395d6eff3053606fdd8794c5c90d96b022/lib/model.js#L314) of the model data.

Since logic of this piece of code remains untouched from the very beginning - I'm not sure if it is intentional (but rather confusing) decision or a bug that hides for a long time.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.