Repository navigation
Closed
Labels
type: bugDEPRECATED: replace with the "bug" issue type
Description
Issue Creation Checklist
- I understand that my issue will be automatically closed if I don't fill in the requested information
- I have read the contribution guidelines
Bug Description
When using Model.bulkCreate, DataTypes.DATE column is returning string.
Reproducible Example
class Post extends Model {
declare id?: number;
declare dateValue: Date;
}
Post.init(
{
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
dateValue: DataTypes.DATE,
},
{
sequelize,
modelName: "Post",
},
);
const resCreate = await Post.create({ dateValue: new Date() });
const resCreateBulk = await Post.bulkCreate([{ dateValue: new Date() }]);
const resCreateBulk0 = resCreateBulk[0]!;
expect(resCreate.dateValue).to.be.instanceOf(Date);
// `dateValue` should be `Date`, but it's `string`
expect(resCreateBulk0.dateValue).not.to.be.instanceOf(Date);
expect(resCreateBulk0.dateValue).to.be.instanceOf(Date);Here is the link to the SSCCE for this issue: link
I do not know why CI is returning success. It looks like it's not testing at all, since there are
this 2 lines in code, in which one will always fails
expect(resCreateBulk0.dateValue).not.to.be.instanceOf(Date);
expect(resCreateBulk0.dateValue).to.be.instanceOf(Date);Also there is no SSCCE done without errors! or SSCCE done with error (see above). in logs.
What do you expect to happen?
dateValue should be Date when creating with bulkCreate
What is actually happening?
dateValue is string when creating with bulkCreate
dateValue is Date when creating with create
Sequelize 7 test failed
AssertionError: expected '2023-02-02 19:02:17.224+00' to be an instance of Date
Environment
- Sequelize version: 7.0.0-alpha.21 ... Also happens in 7.0.0-alpha.20. It does not happen in 7.0.0-alpha.10
- Node.js version: v18.13.0
- If TypeScript related: TypeScript version: 4.9.4 not related
- Database & Version: postgres 15 for my code, default postgres in sscce
- Connector library & Version:
pg8.9.0 andpg-hstore, since it won't run without it at all
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 will need guidance.
- No, I don't have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
- No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in resolving my issue.
Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.
Activity
WikiRik commentedon Feb 3, 2023
I guess this is related to #15579 and I assume introduced in the big DataTypes migration since it did not happen in alpha.10
ephys commentedon Feb 3, 2023
I think the two issues have the same source.
It looks like bulkCreate & create do not hydrate the value, so the only parsing that happens is based on the database type, not the JS type
In v7, the database-type based parsing returns a string by design to be able to support Temporal (https://github.com/sequelize/sequelize/blob/main/packages/core/src/dialects/postgres/data-types-db.ts#L33-L37). We need to fix bulkCreate & create :)
I'm adding this to our v7 backlog, it's important we fix it before the stable release