From 970d17f98a3b7b4b1fff5fdbc3efc1e5bc5bb6ae Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Thu, 24 Sep 2026 06:39:49 -0400 Subject: [PATCH] fix: a second _seed_seen shadowed the one the recapture tests call (4386) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Run 7422 integration: two #830 tests died with `_seed_seen() got an unexpected keyword argument 'post_id'`. Not those tests' fault — I defined a second `_seed_seen` at the BOTTOM of the module, taking a list of media instead of one key, and Python's last definition wins for every call site in the file including the ones 500 lines above it. Renamed to `_seed_all_seen` and made it loop over the existing one-key helper, so there is one definition of what seeding the ledger means. The nearby failure mode is worth naming: a helper defined below the tests that use it is invisible at the point of use, and shadowing produces a TypeError in code nobody touched. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01LVjrnpQjRgHdvq95rASoiR --- tests/test_patreon_ingester.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/tests/test_patreon_ingester.py b/tests/test_patreon_ingester.py index 2363a6a..774722b 100644 --- a/tests/test_patreon_ingester.py +++ b/tests/test_patreon_ingester.py @@ -1156,14 +1156,16 @@ def _iso(days_ago): return (datetime.now(UTC) - timedelta(days=days_ago)).isoformat() -def _seed_seen(sync_engine, source_id, media): - factory = sessionmaker(sync_engine, expire_on_commit=False) - with factory() as s: - for m in media: - s.add(PatreonSeenMedia( - source_id=source_id, filehash=_ledger_key(m), post_id=m.post_id, - )) - s.commit() +def _seed_all_seen(sync_engine, source_id, media): + """Several media through the module's existing one-key `_seed_seen`. + + A distinct NAME, not a second definition: the first version of this shadowed + `_seed_seen` from the bottom of the file, and the two #830 recapture tests + that pass it a `post_id=` kwarg broke on a TypeError. A helper defined below + the tests that use it is invisible at the point of use. + """ + for m in media: + _seed_seen(sync_engine, source_id, _ledger_key(m), post_id=m.post_id) @pytest.mark.asyncio @@ -1174,7 +1176,7 @@ async def test_a_run_of_seen_items_does_not_stop_a_tick_inside_the_window( around at the second and never looked at the third, which is exactly where an edited post lives.""" seen = [_media(f"p{i}", 1) for i in range(1, 4)] - _seed_seen(sync_engine, source_id, seen) + _seed_all_seen(sync_engine, source_id, seen) client = _FakeClient( [(None, [(m.post_id, [m]) for m in seen])], @@ -1201,7 +1203,7 @@ async def test_the_early_out_still_fires_once_the_walk_is_below_the_horizon( did. Asserted beside the test above because the window is only correct if BOTH conditions are required; either one alone is a different feature.""" seen = [_media(f"p{i}", 1) for i in range(1, 4)] - _seed_seen(sync_engine, source_id, seen) + _seed_all_seen(sync_engine, source_id, seen) client = _FakeClient( [(None, [(m.post_id, [m]) for m in seen])], @@ -1226,7 +1228,7 @@ async def test_a_window_of_zero_is_the_behaviour_that_shipped_before_it( """The off switch. Recent posts, a window of 0 → the walk stops on the count alone, so an operator who wants the old cheap tick has one.""" seen = [_media(f"p{i}", 1) for i in range(1, 4)] - _seed_seen(sync_engine, source_id, seen) + _seed_all_seen(sync_engine, source_id, seen) client = _FakeClient( [(None, [(m.post_id, [m]) for m in seen])], @@ -1252,7 +1254,7 @@ async def test_a_backfill_ignores_the_window_because_it_never_early_outs( every body — a horizon there would be a third answer to a two-answer question.""" seen = [_media(f"p{i}", 1) for i in range(1, 4)] - _seed_seen(sync_engine, source_id, seen) + _seed_all_seen(sync_engine, source_id, seen) client = _FakeClient( [(None, [(m.post_id, [m]) for m in seen])], @@ -1407,7 +1409,7 @@ async def test_a_post_whose_date_will_not_parse_falls_back_to_the_count( into the window. It reads as "not provably recent", which leaves that post on the behaviour it had before the window existed.""" seen = [_media(f"p{i}", 1) for i in range(1, 4)] - _seed_seen(sync_engine, source_id, seen) + _seed_all_seen(sync_engine, source_id, seen) client = _FakeClient( [(None, [(m.post_id, [m]) for m in seen])],