Skip to content

fix(cli): 'enrich-agencies --only ep --portal' skips cleanly, no KeyError (#152) - #200

Merged
alexwolson merged 1 commit into
mainfrom
fix-152-ep-portal-keyerror
Jul 28, 2026
Merged

fix(cli): 'enrich-agencies --only ep --portal' skips cleanly, no KeyError (#152)#200
alexwolson merged 1 commit into
mainfrom
fix-152-ep-portal-keyerror

Conversation

@alexwolson

Copy link
Copy Markdown
Collaborator

Closes #152.

The bug

tb enrich-agencies --only ep --portal raised KeyError('ep'):

only = None if not args.only else {"trca": "trca", "zoo": "toronto-zoo"}[args.only]

EP procures via Bonfire, not a bids&tenders portal (#134), so it has no entry in the
body-name → portal-slug map. --only accepts ep as a real body, so the combination is
reachable — and the KeyError was caught by the surrounding try/except and recorded as a
portal FAILURE for a body that was never supposed to have one, which is what made the
symptom misleading rather than just a crash.

The fix

.get(args.only) plus an explicit clean-skip branch when it returns None for a named body:

portal_slug = {"trca": "trca", "zoo": "toronto-zoo"}.get(args.only)
if args.only and portal_slug is None:
    print(f"  portal listings      : {args.only} has no bids&tenders portal — skipping")
else:
    res = run_portal_capture(conn, record=args.record,
                             only={portal_slug} if portal_slug else None, log=out)
    ...

--only trca --portal / --only zoo --portal and the no---only fan-out are unchanged — the
slug mapping (the reason the lookup existed: the body name and the portal's own slug differ for
the zoo) is preserved verbatim.

Verification

Live, against the exact command from the issue:

ep EP agendas        : 0 (cached)
ep stored : 0 solicitations, 0 awards (+0), 0 bids (+0)
portal listings      : ep has no bids&tenders portal — skipping
suppliers            : 0
exit=0

5 new tests, confirmed genuinely red against the pre-fix code by reverting the fix in place:
the EP test fails with the exact FAILED portal: 'ep' this issue reports, while the other 9
existing/new tests in the file stay green — proving the fix is targeted, not incidentally masking
something else. Restored after.

774 tests passing.

🤖 Generated with Claude Code

https://claude.ai/code/session_01W53WHx8mm2UHuLFAQWeF62

…rror (#152)

EP procures via Bonfire, not a bids&tenders portal (#134), so it has no
entry in the body-name -> portal-slug map. `--only` accepts "ep" (a real
body), so `{"trca": "trca", "zoo": "toronto-zoo"}[args.only]` raised an
uncaught KeyError for that combination -- caught by the surrounding
try/except and recorded as a portal FAILURE for a body that was never
supposed to have one.

`.get(args.only)` plus an explicit clean-skip branch when it returns None
for a named body. `--only trca --portal` / `--only zoo --portal` and the
no-`--only` fan-out are unchanged -- the slug mapping (the reason the
lookup existed) is preserved verbatim.

Verified live against the exact command from the issue:
    ep EP agendas        : 0 (cached)
    ep stored : 0 solicitations, 0 awards (+0), 0 bids (+0)
    portal listings      : ep has no bids&tenders portal — skipping
    suppliers            : 0
    exit=0

5 new tests. Confirmed red against the pre-fix code (the EP test fails
with the exact `FAILED portal: 'ep'` this issue reports; the other 9 stay
green), then restored. 774 tests passing.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W53WHx8mm2UHuLFAQWeF62
@alexwolson
alexwolson merged commit e694e56 into main Jul 28, 2026
1 check passed
@alexwolson
alexwolson deleted the fix-152-ep-portal-keyerror branch July 28, 2026 17:39
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.

Low priority: 'enrich-agencies --only ep --portal' raises a caught KeyError (EP has no portal)

1 participant