Virtual attribute set function can't always get other attributes
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 30/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- javascript, node.js
Research direction
Start by running the linked sequelize-sscce reproduction and comparing it with the example in index.js from sequelize-demo. Trace the virtual attribute setter during the shown assignment orders and Model.update() cases; done means the setter can read the other attributes consistently and the reproduced cases pass.
Written by the indexing model from the issue text.
Description
Issue Creation Checklist
- I understand that my issue will be automatically closed if I don't fill in the requested information
- I have read the contribution guidelines
Bug Description
In a set function on a virtual attribute you can't always get other attributes.
Depending on how the set is triggered the specifics differ. But for example, with Model.update() the set doesn't work properly when the attributes it uses aren't in the 'values' argument (and only if the attributes are specified before the virtual attribute).
See the examples for some specific cases.
Reproducible Example
Here is the link to the SSCCE for this issue: https://github.com/sequelize/sequelize-sscce
Also, a similar example not based on sequelize-sscce: https://github.com/JoakimFFCG/sequelize-demo
(I first did the example without sequelize-sscce, so might as well link that too. Also, it runs all the test cases, not stopping at the first one that fails.)
Example code from https://github.com/JoakimFFCG/sequelize-demo/blob/main/index.js
// Works fine
user.firstName = 'Firstname';
user.setNote = 'Yet other note';
user = await user.save();
console.log(user.note); // It's "Firstname: Yet other note"
// Doesn't work
user.setNote = 'Note!';
user.firstName = 'FN';
user = await user.save();
console.log(user.note); // It's "Firstname: Note!"
console.log(user.firstName); // It's "FN"
What do you expect to happen?
In a set function on a virtual attribute you should always be able to get other attributes.
What is actually happening?
In a set function on a virtual attribute you can't always get other attributes (they are undefined). See the code examples for specifics.
Environment
- Sequelize version: 6.25.6 & 7.0.0-alpha.10
- Node.js version: v18.12.1
- If TypeScript related: TypeScript version: Not typescript related
- Database & Version: Shouldn't be database related
- Connector library & Version: Shouldn't be database related
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 will need guidance.
- No, I don't have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
- No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in resolving my issue.
Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.
- Dominant language
- HTML
- Stars
- 30
- Forks
- 170
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
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.
More from sequelize/website
-
Difficulty 1/5 1-3 hours Newbie friendliness 74/100
-
Update Migration.md Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 55/100
All issues in sequelize/website
Similar issues
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
AXERA-TECH/ax-llm#77 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
games-on-whales/wolf#509 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100