upsert overwrites data with default values on update#3994
upsert overwrites data with default values on update#3994janmeier merged 2 commits intosequelize:masterfrom
Conversation
|
I've updated the PR with a proposed fix. |
There was a problem hiding this comment.
You can use sinon fake timers here, to artifically advance time http://sinonjs.org/docs/#clock
There was a problem hiding this comment.
In this situation I think we need the actual delay so that sequelize can internally get the proper Date() times on both create & upsert. I've used sinon to fake timers before, but iirc sinon can't modify the actual system time which is what we need here.
There was a problem hiding this comment.
We use new Date() internally, and that is exactly what fake timers override :)
There was a problem hiding this comment.
I must be misremembering then, I remember a lot of trouble last time I used these for anything other than extending timers. I'll experiment a bit tomorrow and see if I can get it to work.
There was a problem hiding this comment.
@janmeier definitely misremembered, this worked perfectly!
|
LGTM - just a single comment |
lib/model.js
Outdated
There was a problem hiding this comment.
Purely style: mind using leading commas with a single var statement?
438d8d4 to
7d6d2cc
Compare
|
@janmeier @mickhansen comments addressed |
upsert overwrites data with default values on update
|
Thanks @FredKSchott ! :) |
|
Woot! thanks for the quick responses :) |
|
If you bug @mickhansen then probably yes :) In the meantime you can point your package.json to |
|
Yea good point, I'll point for now. Thanks @janmeier! |
|
Released in |
|
Thanks @mickhansen! |
|
Hi, since this release, the upsert function is not working properly. |
|
@telpalbrox please open a new thread with some code that shows the error |
Currently, a
defaultValueset on the model will be used in every upsert operation. This is fine for when upsert INSERTs, since that is when default values are used/needed. However, upsert is also using defaultValue on INSERT, which is causing data to be overwritten and lost by the default values.I've included a test that is currently broken by this bug, I haven't had time to look into a fix yet.EDIT: fix also added/cc @mickhansen @janmeier (from the last upsert issue we worked on)