Skip to content

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

Closed

Description

@spschul

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: [email protected]
Sequelize version: 3.23.6

Activity

  1. added
    type: bug
    on Dec 3, 2016
  2. sushantdhiman commented on Dec 3, 2016

    @sushantdhiman
    Contributor

    VIRTUAL fields should be removed before passing attributes for saving

  3. added a commit that references this issue on Feb 3, 2017
  4. added a commit that references this issue on Apr 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions