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: 🐛 apply relation functions on count queries #848

Closed
wants to merge 1 commit into from

Conversation

enzalito
Copy link

@enzalito enzalito commented Jun 5, 2023

fixes #597

@@ -923,6 +923,17 @@ func (q *SelectQuery) Count(ctx context.Context) (int, error) {
return 0, q.err
}

if err := q.forEachInlineRelJoin(func(j *relationJoin) error {
j.applyTo(q)
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this function modifies the q. Meaning that it will be applied twice when run with ScanAndCount:

  • first it will be applied by Scan
  • second it will be applied by Count

If that is true, then the query generation becomes racy and unsafe....

Copy link
Author

@enzalito enzalito Sep 12, 2023

Choose a reason for hiding this comment

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

ScanAndCount calls the unexported count function that corresponds to Count on the main branch. If I remember correctly the lines you mention do in fact modify q but they are only run when Count (not count) is called directly.

I made this PR a while ago so I might be missing something, you tell me

@vmihailenco vmihailenco added the question Further information is requested label Sep 10, 2023
Copy link

github-actions bot commented Nov 9, 2024

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. If there is no update within the next 7 days, this pr will be closed. Please feel free to give a status update now, ping for review, when it's ready. Thank you for your contributions!

@github-actions github-actions bot added the stale label Nov 9, 2024
@github-actions github-actions bot closed this Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug : functions in Relation statements are not applied on select queries terminated with Count
2 participants