sequelize: DataTypes.STRING normalization error in Snowflake adapter
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 DataTypes.STRING with the Snowflake dialect in models with @sequelize/core decorators-legacy, I’m receiving an error during normalization of the data type. This occurs when trying to sync the model.
I’m aware that the Snowflake dialect is community maintained, and would be happy to help if I have some guidance!
Reproducible Example
Tried to test this with the SSCCE repo, but struggled with the connection timing out with Snowflake (not an issue I’ve had with my project).
- Create a Sequelize model using the decorators-legacy API
- Use DataTypes.STRING for string attributes
- Connect to Snowflake using the Snowflake dialect
- Call sync() on the model
// Model Definition
import { DataTypes, Model } from "@sequelize/core";
import type { InferAttributes, InferCreationAttributes } from "@sequelize/core";
import {
Attribute,
ColumnName,
PrimaryKey,
Table,
} from "@sequelize/core/decorators-legacy";
@Table({
tableName: "EXAMPLE",
timestamps: false,
underscored: true,
})
export class Example extends Model<
InferAttributes<Example>,
InferCreationAttributes<Example>
> {
@Attribute(DataTypes.STRING)
@PrimaryKey
@ColumnName("TEST")
declare test: string;
}
// Sequelize initialization
const options = {
dialect: SnowflakeDialect,
accessUrl: process.env.SNOWFLAKE_URL,
account: process.env.SNOWFLAKE_ACCOUNT,
role: process.env.SNOWFLAKE_ROLE,
warehouse: process.env.SNOWFLAKE_WAREHOUSE,
username: process.env.SNOWFLAKE_USER,
password: process.env.SNOWFLAKE_PW
define: {
underscored: true,
freezeTableName: true,
},
};
const sequelize = new Sequelize(options);
// This line triggers the error
await Example.sync();
What do you expect to happen?
I expect the Example table to be synced with Snowflake, with the Test column with a string data type.
What is actually happening?
Error Message
TypeError: Expected type to be a string, a DataType class, or a DataType instance, but got STRING {
usageContext: undefined,
options: { length: undefined, binary: false }
}.
at normalizeDataType (/app/node_modules/@sequelize/core/src/abstract-dialect/data-types-utils.ts:47:11)
at Sequelize.normalizeDataType (/app/node_modules/@sequelize/core/src/sequelize-typescript.ts:1212:12)
at Sequelize.validateValue (/app/node_modules/@sequelize/core/src/sequelize-typescript.ts:1200:17)
at SnowflakeQueryGenerator.escape (/app/node_modules/@sequelize/snowflake/node_modules/@sequelize/core/src/abstract-dialect/query-generator-typescript.ts:867:20)
at SnowflakeQueryGenerator.tableExistsQuery (/app/node_modules/@sequelize/snowflake/node_modules/@sequelize/core/src/abstract-dialect/query-generator-typescript.ts:918:118)
at SnowflakeQueryInterface.tableExists (/app/node_modules/@sequelize/snowflake/node_modules/@sequelize/core/src/abstract-dialect/query-interface-typescript.ts:332:37)
at Function.sync (/app/node_modules/@sequelize/core/src/model.js:873:47)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
Environment
- Sequelize version: @sequelize/core: v7.0.0-alpha.45
- Node.js version: Node v22.14.0
- If TypeScript related: TypeScript version: typescript@5.6.3
- Database & Version: Snowflake 9.5.2
- Connector library & Version: @sequelize/snowflake: v7.0.0-alpha.45
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.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (7 by maintainers)
We have talked about this, but I don’t think we have implemented this yet. We are for sure interested in it
No, it doesn’t skip the query. It doesn’t get so far. Which makes sense according to the stack trace of the original error. It goes wrong in the type that is passed to
validateValue, from your logging statement. I guess that’s returned frombestGuessDataTypeOfVal. EDIT: That’s also what you found in your debuggingWhat I don’t understand yet, is why this occurs. We have the following test, which also passes when I add the delimiter (which is not passed to the
escapefunction so does not make a difference); https://github.com/sequelize/sequelize/blob/bd292e34be6dd55a5fe878053075795f46cd334e/packages/core/test/unit/query-generator/table-exists-query.test.ts#L44-L52That also gives back
which it can handle without any issue. So somewhere it is fine in our unit tests, but not when you actually use it.
EDIT: I also ran a test for
queryGenerator.escape('SOFTWARE_TEST')directly and that also works as expectedEDIT2: would be strange, but I’ll test tomorrow using Node 22.14.0 in case that’s an issue
That looks correct. Can you add some additional log statements? I’m interested to see a few things;
valueandtypethat are used in https://github.com/sequelize/sequelize/blob/bd292e34be6dd55a5fe878053075795f46cd334e/packages/core/src/sequelize-typescript.ts#L1191 (the last one before the error)tableExists. I thinkcreateTableis also called (model.js line 877). Can you add log statements around that line and see if it’s being executed without errors? If it doesn’t, add a few log statements in this function to see where it fails; https://github.com/sequelize/sequelize/blob/bd292e34be6dd55a5fe878053075795f46cd334e/packages/core/src/abstract-dialect/query-interface.js#L75-L109Could you set up a debugger on that line in the model.js file and tell me what the contents are of
tableNameandoptions? Based on your scenario I cannot reproduce it with other dialects, so it seems to be a snowflake exclusive issue.@sabinevidal I had a quick look at the resulting error message that you provided. Can you provide me with the tableName and options that are passed to the tableExists function (from model.js line 873)? Maybe I can reproduce it from there.
It might not help directly but a few months back somebody ran the integration test suite on snowflake, maybe one of those errors corresponds to what you are experiencing; https://gist.github.com/pappacena/2da4a918047a47d629312f38d9729205