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

explicitly order results in get_helpful_votes_async #5931

Conversation

escattone
Copy link
Contributor

mozilla/sumo#1479

This PR fixes one of the primary causes of our flaky unit test runs. It turns out the root cause of the flakiness was because the HelpfulVote query in the get_helpful_votes_async view was not ordering the results, so it was left to the whims of Postgres to choose an ordering. So in the end, this turned out to be a MySQL vs. Postgres "gotcha". In MySQL prior to version 8, when using a GROUP BY clause without an explicit ORDER BY clause, an implicit ascending order is always used, which does not obey the SQL standard (i.e., no ordering should be applied). When I converted the query to Postgres a number of months ago, the results were no longer reliably ordered because Postgres does obey the standard, and so doesn't order the results. The solution is to add .order_by("date_created") to the HelpfulVote query.

Copy link
Contributor

@smithellis smithellis left a comment

Choose a reason for hiding this comment

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

Awesome!

@smithellis smithellis merged commit 0df2150 into mozilla:main Mar 29, 2024
2 checks passed
@escattone escattone deleted the fix-ordering-in-get_helpful_votes_async-1479 branch April 5, 2024 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants