fix(cli): import all model modules so SA relationship resolution works
hf-cli admin list crashed on prod with `KeyError: 'Agent'` because the CLI bypassed main.py's startup() which is the only place that imports every model module — User has a relationship target (`Agent`) that SQLAlchemy can't resolve unless its module is imported. Load them all up front in __main__.py (mirrors the main.py import block). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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 <e> [--username <u>] [--full-name <n>]
|
||||
[--password <p>] [--oidc-issuer <url> --oidc-subject <sub>]
|
||||
|
||||
Reference in New Issue
Block a user