Deleting PK column does not prevent MSSQL from ordering by PK on LIMIT 1 queries. #14618
Open
3 of 6 tasks
Labels
dialect: mssql
For issues and PRs. Things that involve MSSQL (and do not involve all dialects).
type: bug
Issue Creation Checklist
Bug Description
Initially observed in PR #14549 . Setting
limit=1
onfindOne
queries exposed a bug related to MSSQL column deletion:The below test deletes the
User.id
column on line 666 🤘. The subsequentfindOne
query sorts by theUser.id
columnsequelize/test/integration/associations/belongs-to.test.js
Lines 662 to 682 in 428a85b
Logging the sql string in
abstract/query-interface.js#select
:Notice
[User].[id]
in the order statement.Diging a bit deeper.
primaryKeyField
is used to order the subqueries. You'll notice in my comment above that the primary key would have been deleted insrc/dialects/mssql/query-generator.js#addLimitAndOffeset
See the following console output.
Not quite sure what the resolution is here. If the PK has been deleted.....
Reproducible Example
Run
yarn start-mssql-latest && yarn build && yarn test-integration-mssql -- --grep "should support a non-primary key as the association column on a target without a primary ke"
, on commit fcbea07b3c92a56fc1bf2d992999f2a582222ef4.What do you expect to happen?
Tests should pass, sorting by primary key might not be necessary.
What is actually happening?
Query attempts to sort by deleted key.
Environment
Would you be willing to resolve this issue by submitting a Pull Request?
Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.
Originally posted by @rharriso in #14549 (comment)
The text was updated successfully, but these errors were encountered: