Repository navigation
Closed
Labels
Description
Issue Creation Checklist
[x ] I have read the contribution guidelines
Bug Description
When you update a Buffer in memory that is stored with sequelize as a Blob, the updated buffer is not saved when you save the model.
SSCCE
const CacheMap = sequelize.define("cachemap", {
mapWidth: {
type: Sequelize.INTEGER,
defaultValue: 512,
},
mapLength: {
type: Sequelize.INTEGER,
defaultValue: 512,
},
data: {
type: Sequelize.BLOB('medium'),
},
});
CacheMap.beforeCreate(async (cachemap, options) => {
// this works
cachemap.data = Buffer.alloc(cachemap.mapWidth * cachemap.mapLength, 0);
});
// init the map, make the change
await CacheMap
.create({
mapWidth: 5,
mapLength: 5,
})
// change value to 12 at offset 3
map.data.writeInt8(12 ,4)
// logging the result to console gives me the correct change
// <Buffer 00 00 00 00 00 00 0c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00>
map.save();
What do you expect to happen?
// retrieve data
CacheMap
.findAll({
where: {}
})
//data would be saved as follows:
<Buffer 00 00 00 00 00 00 0c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00>
What is actually happening?
//data in the database looks like this:
<Buffer 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00>
Additional context
I think the reason is that Sequelize might decide whether to update the blob based on the reference, not based on whether the data is actually changed.
Environment
- Sequelize version: latest
- Node.js version: latest
Bug Report Checklist
How does this problem relate to dialects?
- [x ] I think this problem happens regardless of the dialect.
- I think this problem happens only for the following dialect(s):
- I don't know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time and I know how to start.
- Yes, I have the time but I don't know how to start, I would need guidance.
- No, I don't have the time, although I believe I could do it if I had the time...
- [x ] No, I don't have the time and I wouldn't even know how to start.
Activity
github-actions commentedon Jan 5, 2022
This issue has been automatically marked as stale because it has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, just leave a comment or remove the "stale" label. 🙂
garma83 commentedon Jan 5, 2022
still an issue
ephys commentedon Jan 5, 2022
Sequelize needs you to assign something to
map.datato detect changes. Solution is to callmap.changed('map', true)to force the model to consider that field dirty.