Skip to content

bulkCreate returns string instead of Date in postgres #15640

Closed

Description

@apstanisic

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: pg 8.9.0 and pg-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

  1. added
    pending-approval
    type: bug
    on Feb 2, 2023
  2. WikiRik commented on Feb 3, 2023

    @WikiRik
    Member

    I guess this is related to #15579 and I assume introduced in the big DataTypes migration since it did not happen in alpha.10

  3. ephys commented on Feb 3, 2023

    @ephys
    Member

    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

  4. removed
    pending-approval
    on Feb 3, 2023
  5. moved this to Before v7 in Roadmapon Feb 3, 2023
  6. moved this from Before v7 to v8 in Roadmapon Jun 17, 2023
  7. moved this from v8 to Before v7 in Roadmapon Jun 17, 2023
  8. moved this from Before v7 to Doing (v7) in Roadmapon Jun 17, 2023
  9. moved this from Doing (v7) to Done in Roadmapon Jun 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bug

    Type

    No type

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions