You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect handling of postgres table aliases in where clauses when using non-default schema in >= 7.0.0-alpha.20 #15749
I am using sequelize and postgres and setting a non-default schema (i.e. not public) when initialising sequelize. When I make a find query with a where condition I am seeing that sequelize is aliasing the table (e.g. FROM "schema"."table" as "Alias") and is using that alias in the where clause. However, it is producing an invalid statement by prefixing the alias with the schema (e.g. WHERE "schema"."Alias" ...).
I can not reproduce this in 7.0.0-alpha.19. I had a brief look through the changelog and suspect that #15274 could be a candidate for introducing this regression but have not confirmed.
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.
BaseError [SequelizeBaseError]: Invalid value received for the "where" option. Refer to the sequelize documentation to learn which values the "where" option accepts.
Value: { prop: 'hello, world' }
Is that error expected now? I think it should work from the latest docs. Forcing prop to be cast to ::text does work.
I'm also looking at this issue in the repro rep, cause printed below:
/Users/jeffrey.fowler/development/sequelize-v7-alias-bug/node_modules/@sequelize/core/lib/dialects/abstract/where-sql-builder.js:158
throw new import_base_error.BaseError(`Invalid value received for the "where" option. Refer to the sequelize documentation to learn which values the "where" option accepts.
^
BaseError [SequelizeBaseError]: Invalid value received for the "where" option. Refer to the sequelize documentation to learn which values the "where" option accepts.
Value: { prop: 'hello, world' }
at WhereSqlBuilder.formatWhereOptions (/Users/jeffrey.fowler/development/sequelize-v7-alias-bug/node_modules/@sequelize/core/lib/dialects/abstract/where-sql-builder.js:158:13)
at PostgresQueryGenerator.whereItemsQuery (/Users/jeffrey.fowler/development/sequelize-v7-alias-bug/node_modules/@sequelize/core/lib/dialects/abstract/query-generator-typescript.js:160:33)
at PostgresQueryGenerator.selectQuery (/Users/jeffrey.fowler/development/sequelize-v7-alias-bug/node_modules/@sequelize/core/lib/dialects/abstract/query-generator.js:1059:28)
at PostgresQueryInterface.select (/Users/jeffrey.fowler/development/sequelize-v7-alias-bug/node_modules/@sequelize/core/lib/dialects/abstract/query-interface.js:923:37)
at Entity.findAll (/Users/jeffrey.fowler/development/sequelize-v7-alias-bug/node_modules/@sequelize/core/lib/model.js:959:47)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Entity.findOne (/Users/jeffrey.fowler/development/sequelize-v7-alias-bug/node_modules/@sequelize/core/lib/model.js:1091:12)
at async file:///Users/jeffrey.fowler/development/sequelize-v7-alias-bug/index.js:30:1 {
[cause]: TypeError: Cannot read properties of undefined (reading 'getReach')
at SyntaxNode.getReach (/Users/jeffrey.fowler/development/sequelize-v7-alias-bug/node_modules/bnf-parser/bin/syntax.js:70:50)
at Sequence.parseSingle (/Users/jeffrey.fowler/development/sequelize-v7-alias-bug/node_modules/bnf-parser/bin/parser.js:347:32)
at Sequence.parse (/Users/jeffrey.fowler/development/sequelize-v7-alias-bug/node_modules/bnf-parser/bin/parser.js:271:28)
at Sequence.parse (/Users/jeffrey.fowler/development/sequelize-v7-alias-bug/node_modules/bnf-parser/bin/parser.js:323:25)
at Rule.parse (/Users/jeffrey.fowler/development/sequelize-v7-alias-bug/node_modules/bnf-parser/bin/parser.js:389:28)
at Parser.parse (/Users/jeffrey.fowler/development/sequelize-v7-alias-bug/node_modules/bnf-parser/bin/parser.js:425:29)
at parseAttributeSyntaxInternal (/Users/jeffrey.fowler/development/sequelize-v7-alias-bug/node_modules/@sequelize/core/lib/utils/attribute-syntax.js:97:34)
at memoized (/Users/jeffrey.fowler/development/sequelize-v7-alias-bug/node_modules/lodash/memoize.js:62:23)
at /Users/jeffrey.fowler/development/sequelize-v7-alias-bug/node_modules/@sequelize/core/lib/dialects/abstract/where-sql-builder.js:215:88
at Array.map (<anonymous>)
}
Activity
frostzt commentedon Mar 9, 2023
In your code provided if I remove the
schemafromSequelizeinit options:Now where you initialize the
Entitytable I passed the schema like this:Now it generates this!
Now as far as the other way goes I'll look into it.
ephys commentedon Mar 9, 2023
I wonder if this is fixed in #15598, considering it completely rewrites how WHERE generates
chriswheeldon-peakon commentedon Mar 9, 2023
@ephys I have run my example against your branch locally and I no longer see the issue 🥳
Do you think it is worth attempting to fix this in current master or better to just wait for your PR to land?
ephys commentedon Mar 9, 2023
The PR is ready and is waiting for a review. Considering how horribly complex the old WHERE code was, I would prefer waiting for that PR to land 😅
That being said if you or anyone already knows how to fix it, I have no problem merging an intermediary PR to fix it :)
ephys commentedon Mar 12, 2023
#15598 has been merged :)
chriswheeldon-peakon commentedon Mar 15, 2023
Thank you @ephys! I tested again and my now code now doesn't get as far as generating a query at all. Instead the following code from https://github.com/chriswheeldon-peakon/sequelize-v7-alias-bug gives an error when sequelize parses the where:
Is that error expected now? I think it should work from the latest docs. Forcing prop to be cast to
::textdoes work.ephys commentedon Mar 15, 2023
The error you posted is missing details on what exactly failed, can you check what the "cause" property of the error says?
Some testing frameworks (and older node versions) unfortunately don't print the error cause yet
(I'm not near a computer right now but i'll run the repro once I get to one)
jfow commentedon Mar 15, 2023
I'm also looking at this issue in the repro rep, cause printed below:
ephys commentedon Mar 15, 2023
Ok that is 100% a bug
WikiRik commentedon Mar 15, 2023
Might be due to the new
bnf-parserversion; #15792 (do note that the changelog and GitHub releases is incorrect and ships more to NPM, see https://app.renovatebot.com/package-diff?name=bnf-parser&from=3.1.1&to=3.1.2 )ephys commentedon Mar 15, 2023
I was just about to say this :) Updated bnf-parser in our repo and our tests fail.
We'll pin the dependency for now & look into this