Skip to content

master:fix-previous-value - #7189

Merged
sushantdhiman merged 1 commit into
sequelize:masterfrom
nemisj:master-fix-previous
Feb 4, 2017
Merged

sushantdhiman merged 1 commit into
sequelize:masterfrom
nemisj:master-fix-previous

Conversation

@nemisj

@nemisj nemisj commented Feb 3, 2017 •

Copy link
Copy Markdown

Pull Request check-list

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Does your issue contain a link to 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)?
  • Have you added an entry under Future in the changelog?

Description of change

Previous method of the instance was working incorrectly

@nemisj nemisj mentioned this pull request Feb 3, 2017
3 of 5 tasks

@sushantdhiman sushantdhiman left a comment

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.

Needs changelog, otherwise LGTM

@nemisj
nemisj force-pushed the master-fix-previous branch from 88437a7 to 4dc66ef Compare February 3, 2017 20:17
@codecov-io

codecov-io commented Feb 3, 2017 •

Copy link
Copy Markdown

Codecov Report

Merging #7189 into master will increase coverage by <.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 0c2f20b...09804cc. Read the comment docs.

@nemisj

nemisj commented Feb 3, 2017

Copy link
Copy Markdown
Author

@sushantdhiman , added

Comment thread test/unit/instance/previous.test.js Outdated
, DataTypes = require(__dirname + '/../../../lib/data-types')
, current = Support.sequelize;

describe(Support.getTestDialectTeaser('Instance'), function() {

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.

Space before opening brackets function ()

@nemisj
nemisj force-pushed the master-fix-previous branch from 4dc66ef to 09804cc Compare February 4, 2017 07:47
@nemisj

nemisj commented Feb 4, 2017

Copy link
Copy Markdown
Author

done

@sushantdhiman
sushantdhiman merged commit 729575e into sequelize:master Feb 4, 2017
@BorisKozo

Copy link
Copy Markdown

This fix broke our application :D
Reminded me of this: https://xkcd.com/1172/

@barriber

Copy link
Copy Markdown

Previous function doesn't return the correct values now,

return Promise.map(instances, function(instance) {
          // Record updates in instances dataValues
          Utils._.extend(instance.dataValues, values);
          // Set the changed fields on the instance
          Utils._.forIn(valuesUse, function(newValue, attr) {
            if (newValue !== instance._previousDataValues[attr]) {
              instance.setDataValue(attr, newValue);
            }
          });

instance.dataValues override with the new values in Utils._.extend(instance.dataValues, values);
and in instance.setDataValue(attr, newValue);

Instance.prototype.setDataValue = function(key, value) {
  var originalValue = this.dataValues[key];
  if (!Utils.isPrimitive(value) || value !== originalValue) {
    this.changed(key, true);
  }

  this._previousDataValues[key] = originalValue;
  this.dataValues[key] = value;
};

the _previousDataValues overrided with same new data value

@nemisj

nemisj commented Feb 21, 2017

Copy link
Copy Markdown
Author

@barriber so actually we also have to change that code which sets dataValues directly I guess, into something like:

return Promise.map(instances, function(instance) {
          // Set the changed fields on the instance
          Utils._.forIn(valuesUse, function(newValue, attr) {
              instance.setDataValue(attr, newValue);
          });

in order to guarantee the same data flow into the instance

@barriber

Copy link
Copy Markdown

@janmeier could you please comment if this is the correct solution?

@nemisj

nemisj commented Feb 21, 2017

Copy link
Copy Markdown
Author

@barriber i see that there is a note in changelog.md saying that from 2.0.0. version _previousDataValues must be updated after afterUpdate. But I don't understand this comment completely why it's like that. So i guess this solution is also not good and should be done differently.

Comment thread lib/model.js
@@ -2977,11 +2977,12 @@ class Model {
* @param {any} value
*/
setDataValue(key, value) {

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.

This does't work if you call setDataValue multiple times... previous should return the original value (ie. the value in the DB when the record was fetched), am I wrong?

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.

Ok that was reverted... sorry ^^

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.

6 participants