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

Including a virtual field with no other changed values gives an ER_EMPTY_QUERY error #6356

Closed
spschul opened this Issue Jul 29, 2016 · 1 comment

Comments

2 participants
@spschul

spschul commented Jul 29, 2016

What you are doing?

The code below demonstrates the problem.

var Sequelize = require('sequelize');

var database = new Sequelize( /*fill in database configurations*/ );

var TestModel = database.define('TestModel', {
    realField: Sequelize.INTEGER,
    virtField: {
        type: Sequelize.VIRTUAL,
        get: function() {
            return 4;
        }
    }
}, {
    tableName: 'test_model',
    timestamps: false
});

TestModel.sync();

TestModel.create({ realField: 8 })
    .then(function(result) {
        result.update({ virtField: 4, realField: 6 })
            .then(function() {
                console.log('When the instance has changed, it still works.');
            });
        result.update({ virtField: 4 })
            .then(function() {
                console.log('If virtField has a setter, this will print. Otherwise there\'ll be an error.');
            });
    });

What do you expect to happen?

Since Sequelize doesn't fuss when there's a virtual field without a setter in an update normally, I would assume that intended functionality would be for there to be no error.

What is actually happening?

As-is, my code will work fine for the first update call, the one that changes both realField and virtField. However, the second query will throw an error. It would seem that Sequelize doesn't handle it well when a changed virtual field with no setter is present in the returned object.

If there is a setter function present, e.g. js set: function() {}, there's no error.

It's worth noting that this may be unique to databases without timestamps, because timestamps will presumably always be updated.

Dialect: mysql
Database version: mysql@2.11.1
Sequelize version: 3.23.6

@sushantdhiman sushantdhiman added the bug label Dec 3, 2016

@sushantdhiman

This comment has been minimized.

Member

sushantdhiman commented Dec 3, 2016

VIRTUAL fields should be removed before passing attributes for saving

This was referenced Jan 30, 2017

sushantdhiman added a commit to witem/sequelize that referenced this issue Feb 3, 2017

sushantdhiman added a commit that referenced this issue Feb 3, 2017

V3 Fix issues #6356 (#7164)
* fix 5755 for v3 branch

* fix ER_EMPTY_QUERY error on update with virtual fields

* fix review

* [ci skip] changelog for issue

sushantdhiman added a commit that referenced this issue Feb 3, 2017

Fix issues #6356 on master (#7170)
* fix ER_EMPTY_QUERY error on update with virtual fields for master

* fix review

* [ci skip] Changelog for #6356

mkaufmaner added a commit to mkaufmaner/sequelize that referenced this issue Apr 25, 2017

Fix issues sequelize#6356 on master (sequelize#7170)
* fix ER_EMPTY_QUERY error on update with virtual fields for master

* fix review

* [ci skip] Changelog for sequelize#6356
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment