fix: Fix proposal order issue on "recent" - #1008
Merged
Merged
Conversation
AyakorK
marked this pull request as ready for review
July 21, 2026 11:48
moustachu
approved these changes
Jul 24, 2026
moustachu
added a commit
that referenced
this pull request
Jul 24, 2026
* fix: Fix proposal order when ids are multi-matching (133 -> 1133) * fix: Test failing --------- Co-authored-by: moustachu <moustachu@opensourcepolitics.eu>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
🎩 Description
Fixes unstable/incorrect sort order on the public proposals index (
?order=recent,az,za, etc.), which caused old proposals to sometimes appear ahead of much more recent ones.Two separate bugs, both fixed:
proposals_controller_extends.rbusedposition(id::text in '...')to preserve sort order after pagination. Since that's a plain substring match, a short ID (e.g.133) that's a substring of a longer, more recent ID (e.g.2133) gets sorted next to it, regardless of actual date. Replaced witharray_position(...), which matches IDs exactly instead of as text.recent,most_voted,az, etc.) had a tie-breaker. When several proposals tie on the sorted column (samepublished_atfrom an import, several proposals with 0 votes, etc.), Postgres falls back to physical row order, which isn't stable. Added.order(id: :desc)as a tie-breaker via aprependedreorder.Also found along the way: our
ProposalsControllerExtendsoverride was being silently overwritten on every request bydecidim_awesome'sMemoizeExtraFieldsconcern. Switched it fromincludetoprependto fix that.Testing
In
rails console, on a Proposals component:Expected, on
/proposals?order=recent:Also check
/proposals?order=azfor tied/duplicate titles — order should stay stable across reloads.📌 Related Issues
Tasks
reordermethod for all sort options