Skip to content
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

Merged
merged 10 commits into from Feb 13, 2020

Conversation

papb
Copy link
Member

@papb papb commented Jan 23, 2020

Pull Request check-list

Please make sure to review and check all of these items:

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Did you update the typescript typings accordingly (if applicable)?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

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 because other 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 putting fix(find-all) in the actual commit message, but on squash-and-merge that won't matter much.

@papb papb added breaking change status: awaiting maintainer type: other labels Jan 23, 2020
@sushantdhiman
Copy link
Contributor

@sushantdhiman sushantdhiman commented Jan 24, 2020

Tests are breaking. I don't think it is a good idea, what if you got includes or scopes are injecting attributes.

@papb papb force-pushed the throw-on-empty-attrs branch 5 times, most recently from 42b53bf to 549088d Compare Jan 24, 2020
@papb papb force-pushed the throw-on-empty-attrs branch from 549088d to 30fa13a Compare Jan 25, 2020
@sushantdhiman sushantdhiman added status: in discussion and removed status: awaiting maintainer labels Jan 25, 2020
@codecov
Copy link

@codecov codecov bot commented Jan 25, 2020

Codecov Report

Merging #11867 into master will decrease coverage by 6.19%.
The diff coverage is 60.37%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
lib/dialects/mssql/query-generator.js 2.82% <0%> (-93.11%) ⬇️
lib/dialects/mariadb/data-types.js 100% <100%> (ø) ⬆️
lib/data-types.js 91.37% <100%> (+0.02%) ⬆️
lib/dialects/mariadb/query-generator.js 100% <100%> (ø) ⬆️
lib/dialects/mysql/query-generator.js 97.61% <100%> (-0.22%) ⬇️
lib/utils.js 98.36% <100%> (ø) ⬆️
lib/dialects/mysql/data-types.js 98.43% <100%> (ø) ⬆️
lib/dialects/abstract/query-generator.js 95.84% <100%> (-1.2%) ⬇️
lib/utils/join-sql-fragments.js 82.6% <82.6%> (ø)
lib/dialects/mssql/query-interface.js 8.69% <0%> (-91.31%) ⬇️
... and 13 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d23ed1c...901b94d. Read the comment docs.

@papb
Copy link
Member Author

@papb papb commented Jan 25, 2020

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!

@papb papb added status: awaiting maintainer and removed status: in discussion labels Jan 25, 2020
@papb papb requested a review from sushantdhiman Jan 25, 2020
@@ -2019,7 +2020,26 @@ class QueryGenerator {
return { mainQueryOrder, subQueryOrder };
}

_ensureNonemptySelectClause(attributes, extraInfo = {}) {
Copy link
Contributor

@sushantdhiman sushantdhiman Feb 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_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, ' '));
}

Copy link
Member Author

@papb papb Feb 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sushantdhiman Done, thanks 👍

@sushantdhiman sushantdhiman added status: awaiting response and removed status: awaiting maintainer labels Feb 4, 2020
@papb papb requested a review from sushantdhiman Feb 6, 2020
@papb papb added status: awaiting maintainer and removed status: awaiting response labels Feb 6, 2020
@papb papb requested a review from sushantdhiman Feb 8, 2020
@sushantdhiman sushantdhiman merged commit bbf9139 into sequelize:master Feb 13, 2020
2 of 4 checks passed
@sushantdhiman sushantdhiman removed the status: awaiting maintainer label Feb 13, 2020
@papb papb deleted the throw-on-empty-attrs branch Feb 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change type: other
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants