Repository: sequelize/sequelize

Issue #15579: Model.save returns object subtypes instead of saved subtypes
Created: 2023-01-19T15:07:48Z
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 saving a previously created object of a model using the build method the returned object of the save method includes the saved fields in the database but not the datatypes does not match with the saved datatype field/value.
For instance, if you build a Restaurant model, that includes some shipping costs with an object where shipping costs is a string, and then saved, these shipping costs are returned as a string, eventhough this field is a double in the database and it has been saved as a double.
Reproducible Example
req.body = { name: "Restaurant name", shippingCosts: "3.5",  restaurantCategoryId: "1"}
const newRestaurant = Restaurant.build(req.body)
try {
const restaurant = await newRestaurant.save()
/* returned restaurant is: {  createdAt: "2023-01-19T15:01:14.604Z",
updatedAt: "2023-01-19T15:01:14.604Z",
id: 16,
name: "RestaurantName",
shippingCosts: "3.5",
restaurantCategoryId: "1",
} */
res.json(restaurant)
catch (err) {
res.status(500).send(err)
}
What do you expect to happen?
I expect that datatypes  of the subfields matches the datatypes of the table fields of the database.
What is actually happening?
Built/saved objects from an object where doubles/ints are represented as a string are returned as strings, instead of doubles/ints
Environment

Sequelize version: 6.28.0 (macos)
Node.js version: 14.17.6 (macos)
If TypeScript related: TypeScript version:
Database & Version: Mariadb 10.8.3_1 (macos)
Connector library & Version: 3.3.2 (macos)

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.

Duplicate issue #15640: bulkCreate returns string instead of Date in postgres
Created: 2023-02-02T19:08:00Z
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.

Closing comment (2023-02-03T06:59:20Z): I guess this is related to #15579 and I assume introduced in the big DataTypes migration since it did not happen in alpha.10