sequelize-sscce
sequelize-sscce copied to clipboard
Query type changed by comment
In the code we execute two identical queries. One of them has a comment at the beginning. Despite passing the type of the query, sequelize changes the type automatically based on the contents of the query: https://github.com/sequelize/sequelize/blob/d047f3275a451df73294f222c8a2c99ffdd22299/src/dialects/abstract/query.js#L203-L204 This causes the query type to be different depending on if there is a comment at the beginning. As a result, the return value is different.
Note that if the SQL starts with "insert into" it is considered to be an insert statement according to the code linked above.
However, this may not be true in case of an UPSERT in postgresql as that can do one of {insert, update, nothing} even if the statement starts with an "insert into".
Output:
2022-09-08T09:15:00.4952884Z -------------------------------------------------------------
2022-09-08T09:15:00.4962403Z ===== Running SSCCE for POSTGRES with Sequelize v6.21.4 =====
2022-09-08T09:15:00.4964965Z -------------------------------------------------------------
2022-09-08T09:15:00.4965478Z
2022-09-08T09:15:01.3344971Z [Sequelize] Executed (default): DROP TABLE IF EXISTS "Foos" CASCADE; [Elapsed time: 1 ms]
2022-09-08T09:15:01.3345657Z
2022-09-08T09:15:01.3440592Z [Sequelize] Executed (default): SELECT DISTINCT tc.constraint_name as constraint_name, tc.constraint_schema as constraint_schema, tc.constraint_catalog as constraint_catalog, tc.table_name as table_name,tc.table_schema as table_schema,tc.table_catalog as table_catalog,tc.initially_deferred as initially_deferred,tc.is_deferrable as is_deferrable,kcu.column_name as column_name,ccu.table_schema AS referenced_table_schema,ccu.table_catalog AS referenced_table_catalog,ccu.table_name AS referenced_table_name,ccu.column_name AS referenced_column_name FROM information_schema.table_constraints AS tc JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name WHERE constraint_type = 'FOREIGN KEY' AND tc.table_name = 'Foos' AND tc.table_catalog = 'sequelize_test' [Elapsed time: 7 ms]
2022-09-08T09:15:01.3446625Z
2022-09-08T09:15:01.3446996Z [Sequelize] Executed (default): DROP TABLE IF EXISTS "Foos" CASCADE; [Elapsed time: 0 ms]
2022-09-08T09:15:01.3447211Z
2022-09-08T09:15:01.3455222Z [Sequelize] Executed (default): DROP TABLE IF EXISTS "Foos" CASCADE; [Elapsed time: 0 ms]
2022-09-08T09:15:01.3455676Z
2022-09-08T09:15:01.3515824Z [Sequelize] Executed (default): CREATE TABLE IF NOT EXISTS "Foos" ("id" SERIAL , "name" TEXT, PRIMARY KEY ("id")); [Elapsed time: 4 ms]
2022-09-08T09:15:01.3516314Z
2022-09-08T09:15:01.3542905Z [Sequelize] Executed (default): SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) AS definition FROM pg_class t, pg_class i, pg_index ix, pg_attribute a WHERE t.oid = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid AND t.relkind = 'r' and t.relname = 'Foos' GROUP BY i.relname, ix.indexrelid, ix.indisprimary, ix.indisunique, ix.indkey ORDER BY i.relname; [Elapsed time: 2 ms]
2022-09-08T09:15:01.3543855Z
2022-09-08T09:15:01.3583938Z [Sequelize] Executed (default): INSERT INTO "Foos" (id, name)
2022-09-08T09:15:01.3584749Z VALUES (1, 'steve')
2022-09-08T09:15:01.3585208Z ON CONFLICT (id) DO UPDATE
2022-09-08T09:15:01.3586560Z SET name='steve'
2022-09-08T09:15:01.3589888Z RETURNING id, name [Elapsed time: 1 ms]
2022-09-08T09:15:01.3590264Z
2022-09-08T09:15:01.3594011Z [Sequelize] Executed (default): -- HAX
2022-09-08T09:15:01.3594633Z INSERT INTO "Foos" (id, name)
2022-09-08T09:15:01.3595097Z VALUES (1, 'steve')
2022-09-08T09:15:01.3595563Z ON CONFLICT (id) DO UPDATE
2022-09-08T09:15:01.3693689Z SET name='steve'
2022-09-08T09:15:01.3699063Z RETURNING id, name [Elapsed time: 1 ms]
2022-09-08T09:15:01.3702966Z
2022-09-08T09:15:01.3705731Z [ [ { id: 1, name: 'steve' } ], 1 ] [ [ { id: 1, name: 'steve' } ],
2022-09-08T09:15:01.3708329Z Result {
2022-09-08T09:15:01.3710771Z command: 'INSERT',
2022-09-08T09:15:01.3713184Z rowCount: 1,
2022-09-08T09:15:01.3715571Z oid: 0,
2022-09-08T09:15:01.3717945Z rows: [ [Object] ],
2022-09-08T09:15:01.3720389Z fields: [ [Field], [Field] ],
2022-09-08T09:15:01.3722835Z _parsers: [ [Function: parser], [Function: noParse] ],
2022-09-08T09:15:01.3725436Z _types: TypeOverrides { _types: [Object], text: {}, binary: {} },
2022-09-08T09:15:01.3727873Z RowCtor: null,
2022-09-08T09:15:01.3730232Z rowAsArray: false } ]
2022-09-08T09:15:01.3732666Z Sequelize 6 test failed
2022-09-08T09:15:01.3735520Z { AssertionError: expected [ [ { id: 1, name: 'steve' } ], 1 ] to deeply equal [ [ { id: 1, name: 'steve' } ], …(1) ]
2022-09-08T09:15:01.3737291Z at Proxy.assertEql (/home/runner/work/sequelize-sscce/sequelize-sscce/node_modules/chai/lib/chai/core/assertions.js:1096:10)
2022-09-08T09:15:01.3739097Z at Proxy.methodWrapper (/home/runner/work/sequelize-sscce/sequelize-sscce/node_modules/chai/lib/chai/utils/addMethod.js:57:25)
2022-09-08T09:15:01.3740863Z at doAsserterAsyncAndAddThen (/home/runner/work/sequelize-sscce/sequelize-sscce/node_modules/chai-as-promised/lib/chai-as-promised.js:289:22)
2022-09-08T09:15:01.3742645Z at Proxy.<anonymous> (/home/runner/work/sequelize-sscce/sequelize-sscce/node_modules/chai-as-promised/lib/chai-as-promised.js:255:20)
2022-09-08T09:15:01.3744451Z at Proxy.overwritingMethodWrapper (/home/runner/work/sequelize-sscce/sequelize-sscce/node_modules/chai/lib/chai/utils/overwriteMethod.js:78:33)
2022-09-08T09:15:01.3746241Z at Proxy.assertEqual (/home/runner/work/sequelize-sscce/sequelize-sscce/node_modules/chai/lib/chai/core/assertions.js:1035:12)
2022-09-08T09:15:01.3747122Z at Proxy.methodWrapper (/home/runner/work/sequelize-sscce/sequelize-sscce/node_modules/chai/lib/chai/utils/addMethod.js:57:25)
2022-09-08T09:15:01.3748267Z at doAsserterAsyncAndAddThen (/home/runner/work/sequelize-sscce/sequelize-sscce/node_modules/chai-as-promised/lib/chai-as-promised.js:289:22)
2022-09-08T09:15:01.3752125Z at Proxy.<anonymous> (/home/runner/work/sequelize-sscce/sequelize-sscce/node_modules/chai-as-promised/lib/chai-as-promised.js:255:20)
2022-09-08T09:15:01.3753880Z at Proxy.overwritingMethodWrapper (/home/runner/work/sequelize-sscce/sequelize-sscce/node_modules/chai/lib/chai/utils/overwriteMethod.js:78:33)
2022-09-08T09:15:01.3754379Z message:
2022-09-08T09:15:01.3755100Z 'expected [ [ { id: 1, name: \'steve\' } ], 1 ] to deeply equal [ [ { id: 1, name: \'steve\' } ], …(1) ]',
2022-09-08T09:15:01.3758487Z showDiff: true,
2022-09-08T09:15:01.3758895Z actual: [ [ [Object] ], 1 ],
2022-09-08T09:15:01.3759310Z expected:
2022-09-08T09:15:01.3761881Z [ [ [Object] ],
2022-09-08T09:15:01.3762273Z Result {
2022-09-08T09:15:01.3762680Z command: 'INSERT',
2022-09-08T09:15:01.3765296Z rowCount: 1,
2022-09-08T09:15:01.3765625Z oid: 0,
2022-09-08T09:15:01.3765977Z rows: [Array],
2022-09-08T09:15:01.3768532Z fields: [Array],
2022-09-08T09:15:01.3768944Z _parsers: [Array],
2022-09-08T09:15:01.3769416Z _types: [TypeOverrides],
2022-09-08T09:15:01.3771841Z RowCtor: null,
2022-09-08T09:15:01.3772225Z rowAsArray: false } ],
2022-09-08T09:15:01.3774856Z operator: 'deepStrictEqual' }