sequelize / sequelize/sequelize
findOrCreate Creating New Record When Sending a Floating Point Field
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 30.4k
- Forks
- 4.3k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 68
Description
What are you doing?
Single table without associations
db.cidades.findOrCreate({
where: {
nome: 'Cidade do Pequi',
isuber: 1,
latitude: 12,
longitude: 24.02,
estados_idestados: 1
}
}).spread((item, created)=>{
res.send({
item,
created
})
}).catch(error => {
//next(error);
});
What do you expect to happen?
The findOrCreate does not create a new record when it already exists, the problem occurs when a floating-point value is sent (ex: 12.04)
What is actually happening?
In findOrCreate when passing a floating-point number as options, it always creates a new record, even if it already has a record with the same data
In this first print, in longitude I'm passing the value 24 as an integer, this is a record that already exists. Then he correctly just searched the registry and showed that it was not re-created. (Example 1).

When I pass a floating-point value, as in the example the longitude (24.02) always creates a new record (Example 2).

Repeating the data from Example 2, instead of finding findOrCreate is creating a new record, this happens only when passing a floating-point value.

Output, either JSON or SQL
Executing (e7fa7a0c-4165-40a8-9036-67350a29a307): COMMIT;
Executing (0ea6c31e-0071-471e-a783-3c443d518d5c): START TRANSACTION;
Executing (0ea6c31e-0071-471e-a783-3c443d518d5c): SELECT idcidades, nome, latitude, longitude, idclimatempo, isuber, estados_idestados, createdAt, updatedAt FROM cidades AS cidades WHERE cidades.nome = 'Cidade do Pequi' AND cidades.isuber = 1 AND cidades.latitude = '12' AND cidades.longitude = '24.02' AND cidades.estados_idestados = 1 LIMIT 1;
Executing (0ea6c31e-0071-471e-a783-3c443d518d5c): INSERT INTO cidades (idcidades,nome,latitude,longitude,isuber,estados_idestados,createdAt,updatedAt) VALUES (DEFAULT,?,?,?,?,?,?,?);
Executing (0ea6c31e-0071-471e-a783-3c443d518d5c): COMMIT;
Dialect: mysql
Dialect version: "mysql": "^2.16.0", "mysql2": "^1.6.5",
Database version: mysql Ver 14.14 Distrib 5.7.25, for Linux (x86_64) using EditLine wrapper
Sequelize version: "^5.2.1",
Contributor guide
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.
Research direction
The issue names Sequelize's findOrCreate entry point and provides a MySQL SELECT/INSERT trace; begin by reproducing the query with the floating-point longitude against MySQL 5.7.25. No repository file or test is named, so completion should be verified by confirming that repeated findOrCreate calls do not create duplicate records when floating-point values match.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, mysql, nodejs
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100