[Bug] th-cli: don't call GET /api/v1/version on every invocation - #123
Conversation
click.version_option's message param is evaluated eagerly at decoration (i.e. import) time, so get_extended_help() -> get_versions() hit the backend on every th-cli invocation (--help, subcommands, etc.), not just --version. When the backend is unreachable, this stalled every command until the HTTP client timed out. Replace it with a hand-rolled eager --version option whose callback only runs get_extended_help() when --version is actually passed.
|
Understand this PR’s impact Explore downstream dependencies and potential security impact with Blast Radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe root CLI now uses an eager Priority: ⬇️ Low 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Tick the box to add this pull request to the merge queue (same as
|
Summary
th-cliwas callingGET /api/v1/versionon every invocation (--help,subcommands, etc.), not just
--version. When the backend is unreachable,every command hangs until the HTTP client times out.
Root cause
click.version_option(message=get_extended_help())evaluatesmessageeagerly, at decoration (i.e. module import) time — so
get_extended_help()(which calls
get_versions()and hits the backend) ran on everyth-cliinvocation, regardless of which flag/subcommand was used.
Fix
Replace
click.version_optionwith a hand-rolled eager--versionoptionwhose callback only calls
get_extended_help()when--versionis actuallypassed (and is skipped during
ctx.resilient_parsing, e.g. shellcompletion).
Testing
tests/test_main.py:--help/no-args never callget_versions();--versiondoes call it and still exits 0 with the existing"Not able to retrieve versions from server." fallback if the backend call
raises.
th-cli --helpreturns instantly with the backend down,and
th-cli --versionstill prints CLI + backend version info as before.mypy,black,isort,flake8all pass.Closes #1005