fix app startup event (#7554)

This commit is contained in:
Danglewood
2026-06-24 13:48:42 -07:00
committed by GitHub
parent 3160a84ad0
commit f6ad868abd
7 changed files with 121 additions and 35 deletions

View File

@@ -2,6 +2,7 @@
# pylint: disable=W0212,W0613
from contextlib import asynccontextmanager
from typing import Any
from openbb_core.app.model.command_context import CommandContext
@@ -19,6 +20,12 @@ router = Router(prefix="")
COT_CHOICES: list[dict[str, str | dict[str, str | None]]] = []
@asynccontextmanager
async def _cot_router_lifespan(_):
await build_choices()
yield
async def build_choices():
"""Build the choices for Workspace."""
# pylint: disable=import-outside-toplevel
@@ -28,10 +35,17 @@ async def build_choices():
choices: list[dict[str, str | dict[str, str | None]]] = []
for d in contracts:
description = (
f"{getattr(d, 'subcategory', '').strip() or getattr(d, 'commodity_name', '').strip()}"
f" | {getattr(d, 'code', '').strip()}"
)
choice: dict[str, str | dict[str, str | None]] = {
"label": d.name.strip(), # type: ignore
"value": d.code.strip(), # type: ignore
"extraInfo": {"description": f"{d.subcategory.strip()} | {d.code.strip()}", "rightOfDescription": ""}, # type: ignore
"label": getattr(d, "name", "").strip(),
"value": getattr(d, "code", "").strip(),
"extraInfo": {
"description": description,
"rightOfDescription": "",
},
}
choices.append(choice)
@@ -40,7 +54,7 @@ async def build_choices():
COT_CHOICES = choices
router.api_router.add_event_handler("startup", build_choices)
router.api_router.lifespan_context = _cot_router_lifespan
async def get_cot_choices() -> list[dict[str, str | dict[str, str | None]]]: