error updating an instance because of integer id treated as string
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- javascript
- Domain
- databases
Research direction
Start with the Sequelize model definition and the update and association paths described in the report, then inspect the generated SQL and the integer values returned from CockroachDB. Reproduce the failing updates and verify that the database receives the exact id value without an unsupported integer-to-string comparison or association mismatch.
Written by the indexing model from the issue text.
Description
When I do an update from its instance
User.findOne({ where: { email: "[email protected]" } }).then(user => {
user.update({ password })
})
It triggers an error saying
SequelizeDatabaseError: unsupported comparison operator: <int> = <string>
Because it tries to do this query
UPDATE "user" SET "name"='My name',"reset_at"='2017-07-28 07:04:52.688 +00:00',"updated_at"='2017-07-28 07:04:52.706 +00:00' WHERE "id" = '265875070405378049'
Notice quotes between id '265875070405378049' where it should be an integer instead of string. I have the same error when I am trying to update the association such as
user.getProfile().then(profile => {
profile.update({ name })
})
The closest workaround I found is from this comment by setting require('pg').defaults.parseInt8 = true. I do get an integer id when doing the above query, but the weird thing is I do not get the right id.
For example if my id in db is 265875070405378049 the query produces something like ... WHERE "id" = 265875070405378050. Most of the time it uses an integer +/- 1 of the actual id. Same thing going on when I create a record with association. the User.id will be something like 265923186502860801 but the user_id in Profile will be like 265923186502860800
For the record my model is as simple as
const User = sequelize.define('user', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
name: Sequelize.STRING,
}, {
underscored: true,
constraints: false,
timestamps: true
})
- Dominant language
- JavaScript
- Stars
- 54
- Forks
- 18
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from cockroachdb/sequelize-cockroachdb
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
-
Difficulty 1/5 Under an hour Newbie friendliness 45/100
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
cockroachdb/sequelize-cockroachdb#153 · 1 comment ·
All issues in cockroachdb/sequelize-cockroachdb
Similar issues
-
Development server fails with webpack-dev-server 6.1.0Possibly taken @utsxvrai claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
rabbitmq/rabbitmq-website#2733 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 80/100
kentcdodds/kcd-skills#32 ·
-
good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
enhancement frontend good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 2 days