sequelize / sequelize/sequelize
Hook-generated updates to STRING values are not applied to the database
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 30.4k
- Forks
- 4.3k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 68
Description
Issue Description
When model.save() triggers a hook that updates an instance STRING value, Sequelize does not apply this to database. The resulting query does not attempt to update this field.
However, Sequelize does update the javascript model instance.
This is extremely misleading at best: the app believes the database field has been updated, when actually the database field has not changed.
What are you doing?
Here is the link to the SSCCE for this issue: https://github.com/papb/sequelize-sscce/pull/154
NB: Some of the test executions "pass", but it looks like that is only because the SSCCE repo is sometimes running dummy tests instead of the real SSCCE code.
What do you expect to happen?
If a hook fires and includes code to update a field, the field should be updated and that update should be persisted to the database via the UPDATE query.
OR: at the very least, the model instance should remain consistent with Sequelize-facilitated database updates. The instance should never stay divergent after .save(), as it does in the SCCE.
What is actually happening?
When using:
- at least STRING datatypes, and
- beforeValidate or beforeUpdate hooks,
The field is not updated in the database (UPDATE query does not include the hook-generated update). But the sequelize instance is updated.
Additional context
Add any other context or screenshots about the feature request here.
Environment
- Sequelize version: 6.3.3
- Node.js version: 12.20.0
- Operating System: docker-alpine, running on Mac OS Big Sur 11.1
Issue Template Checklist
How does this problem relate to dialects?
- I think this problem happens regardless of the dialect.
- I think this problem happens only for the following dialect(s):
- I don't know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX
The SSCCE testing results show mixed failures and it is unclear which of these (if any) really reflect dialect differences or just issues with the SSCCE repo.
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time and I know how to start.
- [] Yes, I have the time but I don't know how to start, I would need guidance.
- No, I don't have the time, although I believe I could do it if I had the time...
- No, I don't have the time and I wouldn't even know how to start.
This SSCCE is about the limits of my ability, sorry.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the beforeValidate or beforeUpdate behavior using the linked sequelize-sscce example, then trace how save() determines fields for its UPDATE query. Done means a hook-generated STRING change is persisted and the model instance remains consistent, with a regression test covering the behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs, typescript
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100