explicitly order results in get_helpful_votes_async #5931
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theget_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 aGROUP BY
clause without an explicitORDER 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 theHelpfulVote
query.