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

Open
wants to merge 1 commit into
base: master
Choose a base branch
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
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