fix(storage): use 'is not None' checks in feed_filter and entry_filter#393
fix(storage): use 'is not None' checks in feed_filter and entry_filter#393Jaredw2289-svg wants to merge 2 commits intolemon24:masterfrom
Conversation
Empty string feed URLs and entry IDs are valid lookup keys, but the
previous truthiness check (if url:) treated '' as falsy, causing:
- get_feed('') to return arbitrary results instead of raising FeedNotFoundError
- get_entry(('', '')) to return arbitrary results instead of raising EntryNotFoundError
Change to explicit 'is not None' comparisons in feed_filter() and
entry_filter() so empty strings are treated as actual identifiers.
Fixes #392
|
Hi, could you please add some tests for the empty string input? Something based on the repro in the issue description would suffice. Thank you! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #393 +/- ##
=======================================
Coverage 94.27% 94.27%
=======================================
Files 99 99
Lines 13195 13195
Branches 970 970
=======================================
Hits 12439 12439
Misses 683 683
Partials 73 73 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Covers the fix in feed_filter() and entry_filter() (is not None checks):
- test_get_feed_empty_string_url: get_feed('') raises FeedNotFoundError
- test_get_entry_empty_string_ids: get_entry(('','')) raises EntryNotFoundError
Requested by @lemon24 in PR review.
| def test_get_feed_empty_string_url(reader, parser): | ||
| """get_feed('') must raise FeedNotFoundError, not match all feeds. | ||
|
|
||
| Regression test for https://github.com/lemon24/reader/issues/392 — | ||
| feed_filter() used a truthiness check (``if url:``) instead of an | ||
| explicit ``is not None`` check, causing an empty-string URL to be | ||
| silently ignored and the first feed in the DB to be returned. | ||
| """ | ||
| feed = parser.feed(1, datetime(2010, 1, 1)) | ||
| reader._now = lambda: datetime(2010, 1, 1) | ||
| reader.add_feed(feed.url) | ||
|
|
||
| with pytest.raises(FeedNotFoundError) as excinfo: | ||
| reader.get_feed('') | ||
| assert excinfo.value.url == '' | ||
| assert 'no such feed' in excinfo.value.message |
There was a problem hiding this comment.
Can be shortened to just:
def test_get_feed_empty_string_url(reader, parser):
"""https://github.com/lemon24/reader/issues/392"""
reader.add_feed(parser.feed(1))
with pytest.raises(FeedNotFoundError):
reader.get_feed('')We don't need to explain the entire bug (link to issue is enough), we don't care about time, we don't care about the exception message (we can safely assume it was tested by tests for the underlying get_feeds()). Idem for the entries test.
Out of curiosity, is this code AI-generated?
Thank you!
Problem
get_feed('') does not raise FeedNotFoundError, and get_entry(('', '')) does not raise EntryNotFoundError. Instead they return incorrect results by matching against all feeds/entries.
Fixes #392
Solution
In feed_filter() and entry_filter(), change truthiness checks to explicit is not None comparisons:
Empty strings are valid (if pathological) identifiers. The sql query WHERE url = '' correctly returns no rows, causing the expected not-found error to be raised.
Testing
Manually verified: