Sorting Logic Bug in FeedReader.sort_entries() #73
Labels
No labels
bug
contribution welcome
duplicate
enhancement
good first issue
help wanted
invalid
question
upstream
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Reference
marvin8/feed2fedi#73
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Sorting Logic Bug in FeedReader.sort_entries()
The Problem
Feed items aren't being sorted properly when some entries have missing or invalid publication dates.
Where:
src/feed2fedi/collect.py→FeedReader.sort_entries()methodPriority: High (affects posting order)
What's Broken
The current code checks if ALL feed items have valid
published_parseddates before sorting. If even one item hasNoneor an empty value, sorting gets skipped entirely.Current code:
The issue: That second
all(...)check requires everypublished_parsedvalue to be "truthy" (notNone, not empty). Real-world feeds often have items with missing dates.What Should Happen
Feed items should be sorted whenever possible, even if some dates are missing. Items with missing dates should be treated as "earliest" and sorted to the beginning.
The Fix
Replace the current method with:
Why this works:
.get()safely handles missing keys (though we already check they exist)or ()gives missing dates a consistent value (empty tuple) that sorts before real datesImpact
Without this fix:
To Test
Add unit tests for:
Nonedates mixed inNoneQuick Checklist
sort_entries()methodtests/unit/test_collect.pyprek run --all-filesty checkandruff checkpytest tests/unit/test_collect.pynoxfor full CI validationNotes
publish.pyshould be checked for same issueImplemented in version 3.7.3