Skip to content
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

DataLoader issue with $in #48

Open
micahbowerbank opened this issue Jan 17, 2019 · 6 comments
Open

DataLoader issue with $in #48

micahbowerbank opened this issue Jan 17, 2019 · 6 comments
Labels
bug Something isn't working

Comments

@micahbowerbank
Copy link

When I use the following from the example

  const users = await models.User.findAll({
    where: {
      id: {
        $in: keys,
      },
    },
  });

I get the following error

{
  "errors": [
    {
      "message": "Invalid value { '$in': [ 1, 2, 3 ] }",
      "locations": [
        {
          "line": 4,
          "column": 5
        }
      ],
      "path": [
        "accounts",
        0,
        "user"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "stacktrace": [
            "Error: Invalid value { '$in': [ 1, 2, 3 ] }",
            "    at Object.escape (/Users/***/Documents/code/*** /***-server/node_modules/sequelize/lib/sql-string.js:66:11)",
            "    at Object.escape (/Users/***/Documents/code/*** /***-server/node_modules/sequelize/lib/dialects/abstract/query-generator.js:936:22)",
            "    at Object._whereParseSingleValueObject (/Users/***/Documents/code/*** /***-server/node_modules/sequelize/lib/dialects/abstract/query-generator.js:2432:41)",
            "    at Object.whereItemQuery (/Users/***/Documents/code/*** /***-server/node_modules/sequelize/lib/dialects/abstract/query-generator.js:2136:21)",
            "    at Utils.getComplexKeys.forEach.prop (/Users/***/Documents/code/*** /***-server/node_modules/sequelize/lib/dialects/abstract/query-generator.js:1997:25)",
            "    at Array.forEach (<anonymous>)",
            "    at Object.whereItemsQuery (/Users/***/Documents/code/*** /***-server/node_modules/sequelize/lib/dialects/abstract/query-generator.js:1995:35)",
            "    at Object.getWhereConditions (/Users/***/Documents/code/*** /***-server/node_modules/sequelize/lib/dialects/abstract/query-generator.js:2459:19)",
            "    at Object.selectQuery (/Users/***/Documents/code/*** /***-server/node_modules/sequelize/lib/dialects/abstract/query-generator.js:1143:28)",
            "    at QueryInterface.select (/Users/***/Documents/code/*** /***-server/node_modules/sequelize/lib/query-interface.js:1105:27)",
            "    at Promise.try.then.then.then (/Users/***/Documents/code/*** /***-server/node_modules/sequelize/lib/model.js:1598:34)",
            "    at tryCatcher (/Users/***/Documents/code/*** /***-server/node_modules/bluebird/js/release/util.js:16:23)",
            "    at Promise._settlePromiseFromHandler (/Users/***/Documents/code/*** /***-server/node_modules/bluebird/js/release/promise.js:512:31)",
            "    at Promise._settlePromise (/Users/***/Documents/code/*** /***-server/node_modules/bluebird/js/release/promise.js:569:18)",
            "    at Promise._settlePromise0 (/Users/***/Documents/code/*** /***-server/node_modules/bluebird/js/release/promise.js:614:10)",
            "    at Promise._settlePromises (/Users/***/Documents/code/*** /***-server/node_modules/bluebird/js/release/promise.js:694:18)",
            "    at _drainQueueStep (/Users/***/Documents/code/*** /***-server/node_modules/bluebird/js/release/async.js:138:12)",
            "    at _drainQueue (/Users/***/Documents/code/*** /***-server/node_modules/bluebird/js/release/async.js:131:9)",
            "    at Async._drainQueues (/Users/***/Documents/code/*** /***-server/node_modules/bluebird/js/release/async.js:147:5)",
            "    at Immediate.Async.drainQueues [as _onImmediate] (/Users/***/Documents/code/*** /***-server/node_modules/bluebird/js/release/async.js:17:14)",
            "    at processImmediate (timers.js:632:19)"
          ]
        }
      }
    }
  ],
  "data": {
    "accounts": null
  }
}

if I change it to the following then everything works

  const users = await models.User.findAll({
    where: {
      id: keys,
    },
  });

I don't know if this is because I have a newer package or something. But it took me hours to figure it out, so I figured I would share with everyone else

@rwieruch
Copy link
Member

I ran into Sequelize deprecation warnings for all these operators with $. Maybe they deprecated it in the newest version. Which one are you using? Can you try to follow this comment sequelize/sequelize#8417 (comment) as fix?

@matthewboman
Copy link

I got the same error as @micahbowerbank with Sequelize 4.41.2. The solution he gave works.

@rwieruch
Copy link
Member

Thanks for confirming this @crashspringfield I will take this issue into for the next book edition.

In case someone else runs into this issue, please write a comment here and how you worked around the issue :)

@rwieruch rwieruch added the bug Something isn't working label Feb 11, 2019
@davidwyett
Copy link

https://sequelize.org/master/manual/querying.html#where

imported Op module from sequelize and replaced $in with [Op.in]

@JayK19
Copy link

JayK19 commented Jan 14, 2020

So, use [Sequelize.Op.in]: keys instead of $in: keys. It works!

@Davigetz
Copy link

Same Issue but it works when updating to @micahbowerbank solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants