-
Notifications
You must be signed in to change notification settings - Fork 980
Lazy-load CLI commands so augur --help works without DB config
#3661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Augur is an application for open source community health analytics
Options:
--help Show this message and exit.
Commands:
api Commands for controlling the backend API server
backend Commands for controlling the backend API server & data
collection workers
cache Commands for managing redis cache
collection Commands for controlling the backend API server & data
collection workers
config Generate an augur.config.json
csv_utils
db Database utilities
github Github utilities
jumpstart
tasks Commands for controlling the backend API server & data
collection workers
user Support for adding regular users or administrative users works without DB config
Signed-off-by: Hamza <mezohafez1@gmail.com>
e0c3977 to
ecef22b
Compare
augur --help works without DB config
|
@MoralCode I opened a new minimal PR (#3661) that only changes |
yep, thats this PR, thanks! |
|
Can you provide some more detail on why this change was needed? this feels like a very structural change to the object that seems to be underlying almost every CLI command. Was it the importing of this module that is dependent on the database? |
Great question — The issue is that Click builds the help output by calling Some of those command modules have import-time side effects or transitive imports that touch database or config logic, so This change only defers importing the command module until the command is actually invoked. The change is isolated to CLI wiring and avoids touching DB, Redis, or runtime logic. |
Do you have a sense of how much of the CLI is impacted by this? if its only a couple files maybe its worth adjusting how the imports are structured so that click can do its job as intended. |
I actually just tested that exact approach by refactoring backend.py to move all top-level imports (tasks, celery, KeyClient) into local function scope. augur --help still failed with the same DB error. That suggests the issue is transitive and affects more than a couple of files—importing one CLI module often pulls in others that eagerly touch DB/config at import time. Refactoring imports file-by-file would likely turn into whack-a-mole. The lazy proxy approach here provides a safer, structural boundary that ensures --help works without impacting runtime behavior. |
|
Hi @MoralCode Happy to update the PR this way if that sounds reasonable. |
Fixes #3654.
augur --help previously triggered eager imports of CLI command modules via click.MultiCommand.get_command(), which could initialize DB/config and exit before rendering help.
This change returns a lightweight lazy proxy command from get_command(), importing the actual command module only when invoked. short_help is parsed from command source as a best-effort to keep the top-level help informative without importing modules.
Scope is intentionally limited to a single file: augur/application/cli/_multicommand.py. Runtime behavior for actual command execution remains unchanged.