8000 fix(storage): use 'is not None' checks in feed_filter and entry_filter by Jaredw2289-svg · Pull Request #393 · lemon24/reader · GitHub
[go: up one dir, main page]

Skip to content

fix(storage): use 'is not None' checks in feed_filter and entry_filter#393

Closed
Jaredw2289-svg wants to merge 2 commits intolemon24:masterfrom
Jaredw2289-svg:fix/392-empty-string-not-found
Closed

fix(storage): use 'is not None' checks in feed_filter and entry_filter#393
Jaredw2289-svg wants to merge 2 commits intolemon24:masterfrom
Jaredw2289-svg:fix/392-empty-string-not-found

Conversation

@Jaredw2289-svg
Copy link

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:

  • feed_filter: if url: -> if url is not None:
  • entry_filter: if feed_url: -> if feed_url is not None:
  • entry_filter: if entry_id: -> if entry_id is not None:

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:

  • reader.get_feed('') now raises FeedNotFoundError: no such feed: ''
  • reader.get_entry(('', '')) now raises EntryNotFoundError: no such entry: ('', '')
  • reader.get_feed('http://example.com/1') still works correctly
  • reader.get_feed('http://nonexistent.com') still raises FeedNotFoundError

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
@lemon24
Copy link
Owner
lemon24 commented Mar 9, 2026

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
Copy link
codecov bot commented Mar 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.27%. Comparing base (5e0ecb0) to head (269bfb3).
⚠️ Report is 5 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.
Comment on lines +274 to +289
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
Copy link
Owner
@lemon24 lemon24 Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@Jaredw2289-svg Jaredw2289-svg closed this by deleting the head repository Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

get_feed('') and get_entry(('', '')) do not raise not found error

2 participants

0