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

fix(model): count() code generation for distinct rows #11893

Merged
merged 1 commit into from
Feb 21, 2020

Conversation

TimMensch
Copy link
Contributor

@TimMensch TimMensch commented Feb 2, 2020

Pull Request check-list

  • (see below) 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)? (n/a)
  • Did you update the typescript typings accordingly (if applicable)? (n/a)
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description of change

Add code to count() to cause it to create valid SQL when distinct=true and col is unspecified or "*". Otherwise the SQL generated is COUNT(DISTINCT(*)), which is invalid. Issues referenced below were already closed, but the issue hadn't actually been fixed, and it keeps coming up.

Made this change against v5, because I need it ASAP, but the identical change should work against v6. I can submit another PR against master

Notes:

Tested against Postgres 11 only. Three time-based tests failed; it seems like there's a time zone issue? Some other Model/create test failed, also likely due to database version mismatch (permission denied to create extension "uuid-ossp"). Sorry, I don't have time to install the custom Docker Postgres; the related tests passed.

Related tickets: #2713, #6404, #6418, #7344 -- all were "closed", but none were previously actually fixed. Workarounds were listed, but those workarounds don't work at all if you're using Sequelize with Feathers-Sequelize and Sequelize-TypeScript. Besides, Sequelize shouldn't generate bad code when the options aren't perfect.

Add code to count() to cause it to create valid SQL when distinct=true and col is unspecified or "*". Otherwise the SQL generated is COUNT(DISTINCT(*)), which is invalid. Issues referenced below were already closed, but the issue hadn't actually been fixed, and it _keeps coming up_.

Closes: sequelize#2713, sequelize#6404, sequelize#6418, sequelize#7344
@TimMensch
Copy link
Contributor Author

Looking at the failed build, the failure is unrelated to my PR.

@TimMensch
Copy link
Contributor Author

Bump. Any chance we can get this merged?

Copy link
Contributor

@sushantdhiman sushantdhiman left a comment

Choose a reason for hiding this comment

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

LGTM but will need a PR to master before we can merge this to v5

@sushantdhiman sushantdhiman added the status: awaiting response For issues and PRs. OP must respond (or change something, if it is a PR). Maintainers have no action label Feb 20, 2020
@TimMensch
Copy link
Contributor Author

@sushantdhiman #11946 submitted as a PR to master.

@sushantdhiman sushantdhiman merged commit 20e99e1 into sequelize:v5 Feb 21, 2020
@papb papb removed the status: awaiting response For issues and PRs. OP must respond (or change something, if it is a PR). Maintainers have no action label Feb 21, 2020
@sushantdhiman
Copy link
Contributor

🎉 This PR is included in version 5.21.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants