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 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.

@sushantdhiman

This comment has been minimized.

Copy link
Member

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 papb:throw-on-empty-attrs branch 5 times, most recently from 42b53bf to 549088d Jan 24, 2020
@papb papb force-pushed the papb:throw-on-empty-attrs branch from 549088d to 30fa13a Jan 25, 2020
papb added 2 commits Jan 25, 2020
@codecov

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Member Author

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!

@@ -2019,7 +2020,26 @@ class QueryGenerator {
return { mainQueryOrder, subQueryOrder };
}

_ensureNonemptySelectClause(attributes, extraInfo = {}) {

This comment has been minimized.

Copy link
@sushantdhiman

sushantdhiman Feb 4, 2020

Member
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, ' '));
}

This comment has been minimized.

Copy link
@papb

papb Feb 6, 2020

Author Member

@sushantdhiman Done, thanks 👍

papb added 2 commits Feb 6, 2020
@papb papb requested a review from sushantdhiman Feb 6, 2020
papb added 2 commits Feb 8, 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
2 of 4 checks passed
codecov/patch 87.50% of diff hit (target 96.23%)
Details
codecov/project 90.10% (+-6.13%) compared to 0fb4bb1
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@papb papb deleted the papb: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
Linked issues

Successfully merging this pull request may close these issues.

2 participants
You can’t perform that action at this time.