Skip to content

fix(upsert): sets isNewRecord to false when upserting - #12447

Merged
sushantdhiman merged 4 commits into
sequelize:masterfrom
knoid:bugfix/upsert-new
Jul 10, 2020
Merged

sushantdhiman merged 4 commits into
sequelize:masterfrom
knoid:bugfix/upsert-new

Conversation

@knoid

@knoid knoid commented Jun 30, 2020 •

Copy link
Copy Markdown
Contributor

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

I'm having problems on upsert returned instances. Doing a .save() on an instance right after an upsert returns validation error because it tries to insert instead of updating. I think I tracked this error to having isNewRecord as true on that returned instance. I tried fixing it by setting it to false on upsert method but failed on other tests.

@knoid
knoid force-pushed the bugfix/upsert-new branch 8 times, most recently from 5e32cfc to a18eaf7 Compare June 30, 2020 16:17
@sushantdhiman

Copy link
Copy Markdown
Contributor

No travis build on this PR, can you try pushing an empty commit?

@knoid
knoid force-pushed the bugfix/upsert-new branch from a18eaf7 to 1fb7da7 Compare July 1, 2020 12:29
@knoid

knoid commented Jul 1, 2020 •

Copy link
Copy Markdown
Contributor Author

done! check Travis, it fails on MARIADB and I don't know how to fix that without making it fail everywhere else.

@knoid
knoid force-pushed the bugfix/upsert-new branch 3 times, most recently from 3d28419 to 9744a3d Compare July 7, 2020 14:07
@knoid

knoid commented Jul 7, 2020

Copy link
Copy Markdown
Contributor Author

managed to fix all related errors! now it fails on mysql something totally unrelated. Am I in the right path? I needed to set isNewRecord to false manually after the insert because if not, it would not populate default values.

@knoid
knoid force-pushed the bugfix/upsert-new branch from 9744a3d to 9da4b5a Compare July 7, 2020 16:06
@codecov

codecov Bot commented Jul 7, 2020 •

Copy link
Copy Markdown

Codecov Report

Merging #12447 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #12447   +/-   ##
=======================================
  Coverage   96.38%   96.38%           
=======================================
  Files          95       95           
  Lines        9255     9257    +2     
  Branches       61       54    -7     
=======================================
+ Hits         8920     8922    +2     
  Misses        322      322           
  Partials       13       13           
Impacted Files Coverage Δ
src/dialects/mariadb/query.js 87.96% <100.00%> (ø)
src/model.js 96.58% <100.00%> (+<0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc2a08b...8ea4549. Read the comment docs.

@knoid
knoid force-pushed the bugfix/upsert-new branch from 9da4b5a to c287c2b Compare July 7, 2020 16:18
@knoid knoid changed the title fix(upsert): should set isNewRecord to false when upserting fix(upsert): sets isNewRecord to false when upserting Jul 7, 2020
Comment thread src/model.js Outdated
options
);

instance.isNewRecord = false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although here instance === result, we should change naming here. May be rename result to record and then set record.isNewRecord = false

@knoid knoid Jul 8, 2020 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Result is actually [instance, boolean]. Should I do this?

Suggested change
instance.isNewRecord = false;
const [record] = result;
record.isNewRecord = false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that works

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like tests are failing with this commit

Co-authored-by: Ariel Barabas <[email protected]>
@jingsam

jingsam commented Jul 9, 2020

Copy link
Copy Markdown

I encountered same problem. waiting to get this PR to be merged.

@knoid
knoid force-pushed the bugfix/upsert-new branch from abcec4f to 3933b1f Compare July 9, 2020 17:33
@knoid
knoid force-pushed the bugfix/upsert-new branch from 3933b1f to 8ea4549 Compare July 9, 2020 17:43
@sushantdhiman
sushantdhiman merged commit bb30483 into sequelize:master Jul 10, 2020
@sushantdhiman

Copy link
Copy Markdown
Contributor

Please open a PR for v6 branch to get a npm release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants