Fix series sorting for numeric, non-numeric, and range positions#12186
Conversation
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Pull request overview
Updates series seed ordering in the Lists/Series model so that mixed position formats (numeric, non-numeric, and ranges) sort in a more predictable, deterministic way, addressing incorrect ordering on series pages (e.g., 3-4 appearing before 1-2).
Changes:
- Replaces float-based series position sorting with a tuple-based sort key that buckets numeric, non-numeric, and range positions.
- Adds range parsing via regex and additional tie-breakers for deterministic ordering.
- Adds/extends unit test coverage for series sorting across numeric, non-numeric, range, and
Nonepositions.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
openlibrary/core/lists/model.py |
Reworks Series.get_seeds() sorting logic to handle numeric/non-numeric/range positions deterministically. |
openlibrary/tests/core/lists/test_model.py |
Adds a focused test validating the intended ordering across mixed position formats. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
cdrini
left a comment
There was a problem hiding this comment.
Nice looks great! Two suggestions to fix the type error and making the unit tests a bit simpler.
|
@Harshul23 please request review from drini (as I have done now) or tag him when you're ready for review again (which it seems you are) |
|
Thanks I will make sure to re-request a review after addressing changes next time. |
cdrini
left a comment
There was a problem hiding this comment.
Lgtm! Tested on testing.
…series-position-sorting Fix series sorting for numeric, non-numeric, and range positions
Closes #12153
fix
Technical
This PR updates series sorting in
openlibrary/core/lists/model.pyto handle mixedpositionformats more predictably.Previously, the sorting logic reduced
positionto a single float, which worked for simple numeric values but did not handle range-based entries like1-3,22-23, and24-25well.This change replaces the float-based sort key with a tuple-based sort key so series items are ordered as:
For range-based positions, sorting is further stabilized by:
max - min)Testing
Verified with:
Result:
Manual verification:
Screenshot
Sorting behavior was manually verified locally on the affected series page after the fix.
Screen.Recording.2026-03-25.at.1.40.39.AM.mov
Stakeholders
@cdrini @mekarpeles