{"record":{"id":"cef30ff2e9caf9f8","repo":"microsoft/qlib","slug":"please-implement-the-online-models-method","errorCode":null,"errorMessage":"Please implement the `online_models` method.","messagePattern":"Please implement the `online_models` method\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"qlib/workflow/online/utils.py","lineNumber":74,"sourceCode":"    def reset_online_tag(self, recorder: Union[list, object]):\n        \"\"\"\n        Offline all models and set the recorders to 'online'.\n\n        Args:\n            recorder (Union[list,object]):\n                the recorder you want to reset to 'online'.\n\n        \"\"\"\n        raise NotImplementedError(f\"Please implement the `reset_online_tag` method.\")\n\n    def online_models(self) -> list:\n        \"\"\"\n        Get current `online` models\n\n        Returns:\n            list: a list of `online` models.\n        \"\"\"\n        raise NotImplementedError(f\"Please implement the `online_models` method.\")\n\n    def update_online_pred(self, to_date=None):\n        \"\"\"\n        Update the predictions of `online` models to to_date.\n\n        Args:\n            to_date (pd.Timestamp): the pred before this date will be updated. None for updating to the latest.\n\n        \"\"\"\n        raise NotImplementedError(f\"Please implement the `update_online_pred` method.\")\n\n\nclass OnlineToolR(OnlineTool):\n    \"\"\"\n    The implementation of OnlineTool based on (R)ecorder.\n    \"\"\"\n\n    def __init__(self, default_exp_name: str = None):","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/workflow/online/utils.py#L56-L92","documentation":"OnlineTool.online_models is an abstract method of the OnlineTool base class; it should return the list of recorders/models currently tagged 'online'. The base raises NotImplementedError by design. The error occurs when something enumerates online models (strategy workflows, OnlineManager routines) through a tool that never implemented online_models.","triggerScenarios":"Calling tool.online_models() where tool is OnlineTool() or an incomplete subclass; OnlineStrategy.prepare_tasks default docstring flows reading self.tool.online_models; custom OnlineTool backends missing the override.","commonSituations":"Default-constructed OnlineStrategy (its __init__ sets self.tool = OnlineTool()) being driven through an online routine; porting OnlineToolR to a custom registry and forgetting the query method; test doubles that stub only some methods.","solutions":["Use OnlineToolR, whose online_models queries the experiment's recorders filtered by the ONLINE_TAG","Implement online_models(self) -> list in your subclass returning recorders currently marked online","Ensure any OnlineManager routine that runs against your strategy has a fully concrete tool wired in"],"exampleFix":"# before\ntool = OnlineTool()\ntool.online_models()  # NotImplementedError\n\n# after\nfrom qlib.workflow.online.utils import OnlineToolR\ntool = OnlineToolR(default_exp_name='my_exp')\nonline = tool.online_models()","handlingStrategy":"type-guard","validationCode":"from qlib.workflow.online.utils import OnlineTool\n\ndef assert_online_models_implemented(tool):\n    if type(tool).online_models is OnlineTool.online_models:\n        raise TypeError(f'{type(tool).__name__} must implement online_models')","typeGuard":"from qlib.workflow.online.utils import OnlineTool\n\ndef can_list_online(tool) -> bool:\n    return type(tool).online_models is not OnlineTool.online_models","tryCatchPattern":"try:\n    models = tool.online_models()\nexcept NotImplementedError:\n    models = []  # nothing tracked; or re-raise if online state must be known","preventionTips":["Never instantiate OnlineTool where behavior is needed","Construct OnlineToolR with default_exp_name to make online_models work immediately","Encapsulate tool creation in a factory so abstract instances cannot leak"],"tags":["qlib","online-tool","abstract-method","not-implemented"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}