-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
other(find-all): throw on empty attributes #11867
Conversation
Tests are breaking. I don't think it is a good idea, what if you got includes or scopes are injecting attributes. |
42b53bf
to
549088d
Compare
549088d
to
30fa13a
Compare
Codecov Report
@@ Coverage Diff @@
## master #11867 +/- ##
=========================================
- Coverage 96.27% 90.08% -6.2%
=========================================
Files 94 93 -1
Lines 9217 9100 -117
=========================================
- Hits 8874 8198 -676
- Misses 343 902 +559
Continue to review full report at Codecov.
|
Hi @sushantdhiman, you are right, however I still think something could be done about these errors, so I worked on another approach. Tests are passing now, please review again, thanks! |
@@ -2019,7 +2020,26 @@ class QueryGenerator { | |||
return { mainQueryOrder, subQueryOrder }; | |||
} | |||
|
|||
_ensureNonemptySelectClause(attributes, extraInfo = {}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_ensureNonemptySelectClause(attributes, extraInfo = {}) { | |
_throwOnEmptyAttributes(attributes, extraInfo = {}) { | |
if (attributes.length > 0) return; | |
const asPart = extraInfo.as && `as ${extraInfo.as}` || ''; | |
const namePart = extraInfo.modelName && `for model '${extraInfo.modelName}'` || ''; | |
const message = `Attempted a SELECT query ${namePart} ${asPart} without selecting any columns`; | |
throw new sequelizeError.QueryError(message.replace(/ +/g, ' ')); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sushantdhiman Done, thanks 👍
Pull Request check-list
Please make sure to review and check all of these items:
npm run test
ornpm run test-DIALECT
pass with this change (including linting)?Description of change
Closes #11858
This provides a much better error message for the situation described in #11858.
However it is technically a breaking change because on Postgres running
SELECT FROM "Foos"
does not throw (simply yielding an empty array). However from the Sequelize point of view, it should throw (IMO), since why would you run a SELECT query and fetch nothing?Note: The commit as in PR title
other(find-all): throw on empty attributes
is not allowed by commitlint becauseother
is not a valid scope type. However, I am unsure of what choice to make among the valid options, which are build, ci, docs, feat, fix, perf, refactor, revert, style and test, so I leave it for you to decide @sushantdhiman. I ended up puttingfix(find-all)
in the actual commit message, but on squash-and-merge that won't matter much.