diff --git a/app/cli/__main__.py b/app/cli/__main__.py index d4dd5dd..97cc6e0 100644 --- a/app/cli/__main__.py +++ b/app/cli/__main__.py @@ -2,6 +2,26 @@ import sys +def _load_all_models() -> None: + """Import every model module so SQLAlchemy's declarative registry + resolves cross-table relationships (e.g. User.role, User.agent). + + main.py's startup() does the same thing for the web server; the CLI + skips startup() but still queries User → would otherwise hit + `KeyError: 'Agent'` when SA tries to resolve relationship targets. + Keep this list in sync with main.py's startup import list. + """ + from app.models import ( # noqa: F401 + models, webhook, apikey, activity, milestone, notification, worklog, + monitor, role_permission, task, support, meeting, proposal, propose, + essential, agent, calendar, minimum_workload, schedule_type, + schedule_type_special_slot, oidc_settings, + ) + + +_load_all_models() + + USAGE = """Usage: hf-cli admin create-user --email [--username ] [--full-name ] [--password

] [--oidc-issuer --oidc-subject ]