{"record":{"id":"04b5ad869f2300c8","repo":"microsoft/qlib","slug":"both-default-exp-name-and-exp-name-are-none-onlin","errorCode":null,"errorMessage":"Both default_exp_name and exp_name are None. OnlineToolR needs a specific experiment.","messagePattern":"Both default_exp_name and exp_name are None\\. OnlineToolR needs a specific experiment\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/workflow/online/utils.py","lineNumber":183,"sourceCode":"            exp_name (str): the experiment name. If None, then use default_exp_name.\n        \"\"\"\n        exp_name = self._get_exp_name(exp_name)\n        online_models = self.online_models(exp_name=exp_name)\n        for rec in online_models:\n            try:\n                updater = PredUpdater(rec, to_date=to_date, from_date=from_date)\n            except LoadObjectError as e:\n                # skip the recorder without pred\n                self.logger.warn(f\"An exception `{str(e)}` happened when load `pred.pkl`, skip it.\")\n                continue\n            updater.update()\n\n        self.logger.info(f\"Finished updating {len(online_models)} online model predictions of {exp_name}.\")\n\n    def _get_exp_name(self, exp_name):\n        if exp_name is None:\n            if self.default_exp_name is None:\n                raise ValueError(\n                    \"Both default_exp_name and exp_name are None. OnlineToolR needs a specific experiment.\"\n                )\n            exp_name = self.default_exp_name\n        return exp_name\n","sourceCodeStart":165,"sourceCodeEnd":188,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/workflow/online/utils.py#L165-L188","documentation":"OnlineToolR._get_exp_name raises ValueError when both the exp_name argument and the tool's default_exp_name (set in OnlineToolR.__init__) are None. OnlineToolR operates on the recorders of one specific MLflow experiment, so with no experiment name it has nothing to query; the error is a fail-fast guard rather than a silent empty result.","triggerScenarios":"Constructing OnlineToolR() without default_exp_name and then calling any method that resolves the experiment (online_models, update_online_pred, reset_online_tag) without an explicit exp_name; passing exp_name=None explicitly to those methods on a default-less tool; creating RollingStrategy/OnlineManager with a tool that was never given an experiment name.","commonSituations":"Copy-pasting example code that omitted the constructor argument; assuming the tool inherits the experiment from the surrounding Qlib workflow context (it does not); refactoring code and dropping the default_exp_name parameter.","solutions":["Pass the experiment name at construction: OnlineToolR(default_exp_name='my_experiment')","Or pass exp_name explicitly to the method call that raised (e.g. tool.online_models(exp_name='my_experiment') where supported)","Verify the name matches an existing experiment via R.list_experiments() so the next call does not fail with error 540"],"exampleFix":"# before\ntool = OnlineToolR()\ntool.online_models()  # ValueError: both names None\n\n# after\ntool = OnlineToolR(default_exp_name='my_experiment')\ntool.online_models()","handlingStrategy":"validation","validationCode":"from qlib.workflow.online.utils import OnlineToolR\n\ndef make_tool(exp_name: str):\n    if exp_name is None:\n        raise ValueError('exp_name is required for OnlineToolR')\n    return OnlineToolR(default_exp_name=exp_name)","typeGuard":null,"tryCatchPattern":"try:\n    tool.online_models()\nexcept ValueError as e:\n    if 'Both default_exp_name and exp_name are None' in str(e):\n        tool.default_exp_name = 'my_experiment'  # then retry once\n    else:\n        raise","preventionTips":["Always construct OnlineToolR(default_exp_name=...) with a real experiment name","Validate exp_name at configuration load time, not deep inside a routine","Assert the experiment exists via R.list_experiments() before starting online workflows"],"tags":["qlib","online-tool","config","validation"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}