Open kevinburkeshyp opened 9 years ago
Yea, this is a typical race condition that probably needs to just be handled like any other synchronization concern. An UPDATE will still overwrite any values that are specified in the provided "update" object.
Right, but with an UPDATE usually I'm specifying the columns I want to overwrite/clobber. With save() it's implicit, it's easier to miss. For what it's worth I didn't realize the implications for ~5 months of using the ORM
@kevinburkeshyp, PR balderdashy/waterline#1048 should fix this behaviour where only changed fields actually get sent to the DB on .save()
.
say you have two threads which both have a User object in memory. one updates the email, the other updates the phone number. both call
save()
. this turns intoboth threads believe they've saved the new value on the object, however, one of the updates got clobbered by the other one.
probably no plan to fix this behavior, might at least want to document it & explain that you probably want to do an UPDATE w/ only the affected property(ies) if you care about the consistency of your data.