Skip to content
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

fix: Prevent set function to remove saved data when failing to update #13153

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

jctaveras
Copy link

Pull Request check-list

Please make sure to review and check all of these items:

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Did you update the typescript typings accordingly (if applicable)?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description of change

Closes: #13149

These changes prevent the set function to delete the saved data when failing to update with, plush when receiving null it will return destroy the saved data without going through the whole function.

Tests cases

const user = await User.findByPk(1);
user.setTasks([1, 2]);
const tasks = await user.getTasks();
console.log(tasks); // Task[{ id: 1, ... }, { id: 2, ... }]
const user = await User.findByPk(1);
user.addTask(1);
user.setTasks([2]);
const tasks = await user.getTasks();
console.log(tasks); // Task[{ id: 2, ... }]
const user = await User.findByPk(1);
user.setTasks(null);
const tasks = await user.getTasks();
console.log(tasks); // Task[]
const user = await User.findByPk(1);
user.setTasks([1, 2]);
user.setTasks([UNKOWN_TASK_ID]);
const tasks = await user.getTasks();
console.log(tasks); // Task[{ id: 1, ... }, { id: 2, ... }]

@jctaveras jctaveras force-pushed the 13149/belongs-to-many-bug branch 4 times, most recently from f57cee9 to 53015fb Compare March 29, 2021 07:22
@closingin
Copy link
Contributor

closingin commented Jul 7, 2021

Hello @jctaveras !

Sorry for being so late in testing this PR, but I can confirm that it fixes #13149. Thanks a lot for the investigation and the fix 👍

Considering that the issue can generate data loss, I think it would be worth creating a test for it to avoid future regression. What do you think?

@closingin
Copy link
Contributor

Hey @allawesome497 @papb , would any of you be available to take over this PR ? 🙂

@jctaveras
Copy link
Author

Hey @closingin sorry I didn't reply to your comment

Sorry for being so late in testing this PR, but I can confirm that it fixes #13149. Thanks a lot for the investigation and the fix +1 Considering that the issue can generate data loss, I think it would be worth creating a test for it to avoid future regression. What do you think?

I'll take a look at those test soon 😉

@github-actions github-actions bot added the stale label Oct 27, 2021
@closingin
Copy link
Contributor

Hello @jctaveras , any updates on this ? 🙂

@github-actions github-actions bot removed the stale label Nov 1, 2021
@jctaveras
Copy link
Author

@closingin sorry for the long delay.

I was checking at the comment you left regarding test on data loss, but I don't think I quite get it 🤔 as far as I can see everything is covered with the current tests, plus I make the expected changes to the tests so they go according the changes that I've introduced.

@closingin
Copy link
Contributor

closingin commented Nov 6, 2021

Well if it's good for you then it's good for me! We need someone to review the PR though.

@github-actions github-actions bot added the stale label Nov 21, 2021
@github-actions github-actions bot removed the stale label Jul 26, 2022
@ephys ephys changed the title fix(bug): Prevent set function to remove saved data when failing to update fix: Prevent set function to remove saved data when failing to update Mar 24, 2023
@ephys ephys requested a review from a team March 24, 2023 11:02
@jctaveras jctaveras requested a review from a team as a code owner March 18, 2024 23:04
@jctaveras jctaveras requested review from ephys and WikiRik and removed request for a team March 18, 2024 23:04
@sequelize-bot sequelize-bot bot added the conflicted This PR has merge conflicts and will not be present in the list of PRs to review label Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conflicted This PR has merge conflicts and will not be present in the list of PRs to review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

belongsToMany's automatic setters delete data when passed a non-existing id
2 participants