{"record":{"id":"7b5db1bd74f28acc","repo":"microsoft/qlib","slug":"error-e-something-went-wrong-when-deleting-exp","errorCode":null,"errorMessage":"Error: {e}. Something went wrong when deleting experiment. Please check if the name/id of the experiment is correct.","messagePattern":"Error: (.+?)\\. Something went wrong when deleting experiment\\. Please check if the name/id of the experiment is correct\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/workflow/expm.py","lineNumber":418,"sourceCode":"        run_view_type = 1 if kwargs.get(\"run_view_type\") is None else kwargs.get(\"run_view_type\")\n        max_results = 100000 if kwargs.get(\"max_results\") is None else kwargs.get(\"max_results\")\n        order_by = kwargs.get(\"order_by\")\n        return self.client.search_runs(experiment_ids, filter_string, run_view_type, max_results, order_by)\n\n    def delete_exp(self, experiment_id=None, experiment_name=None):\n        assert (\n            experiment_id is not None or experiment_name is not None\n        ), \"Please input a valid experiment id or name before deleting.\"\n        try:\n            if experiment_id is not None:\n                self.client.delete_experiment(experiment_id)\n            else:\n                experiment = self.client.get_experiment_by_name(experiment_name)\n                if experiment is None:\n                    raise MlflowException(\"No valid experiment has been found.\")\n                self.client.delete_experiment(experiment.experiment_id)\n        except MlflowException as e:\n            raise ValueError(\n                f\"Error: {e}. Something went wrong when deleting experiment. Please check if the name/id of the experiment is correct.\"\n            ) from e\n\n    def list_experiments(self):\n        # retrieve all the existing experiments\n        mlflow_version = int(mlflow.__version__.split(\".\", maxsplit=1)[0])\n        if mlflow_version >= 2:\n            exps = self.client.search_experiments(view_type=ViewType.ACTIVE_ONLY)\n        else:\n            exps = self.client.list_experiments(view_type=ViewType.ACTIVE_ONLY)  # pylint: disable=E1101\n        experiments = dict()\n        for exp in exps:\n            experiment = MLflowExperiment(exp.experiment_id, exp.name, self.uri)\n            experiments[exp.name] = experiment\n        return experiments\n","sourceCodeStart":400,"sourceCodeEnd":434,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/workflow/expm.py#L400-L434","documentation":"Raised by ExpManager.delete_exp when the underlying MLflow delete_experiment call fails. The message embeds the original MlflowException text; typical root causes are an experiment id that does not exist, a name lookup returning None (re-raised internally as MlflowException), or backend errors during the delete call.","triggerScenarios":"Calling delete_exp(experiment_id=<wrong-id>) where the id is unknown to the MLflow backend; calling delete_exp(experiment_name=<name that does not exist>); MLflow server rejecting the delete (permissions, network, malformed id); deleting an already-deleted experiment.","commonSituations":"Cleanup scripts that hard-code stale experiment ids; re-running an idempotent teardown after the experiment was already removed; tracking URI mismatch so the delete targets the wrong backend where the experiment never existed.","solutions":["Confirm the experiment exists before deleting: use list_experiments() to get the exact id/name and retry with those values","Check the tracking URI is the one where the experiment lives before calling delete_exp","Treat 'not found' as success in cleanup code: catch ValueError, inspect e.__cause__, and ignore RESOURCE_DOES_NOT_EXIST-style MlflowExceptions","If the experiment is already soft-deleted, skip the call or use client.restore_experiment first if you want to force-delete"],"exampleFix":"# before\nR.delete_exp(experiment_name='alpha158')  # ValueError on wrong name\n\n# after\nexps = R.list_experiments()\nif 'alpha158' in exps:\n    R.delete_exp(experiment_id=exps['alpha158'].id)\nelse:\n    print('already gone')","handlingStrategy":"try-catch","validationCode":"from qlib.workflow import R\n\ndef delete_exp_safe(name: str):\n    exps = R.list_experiments()\n    if name not in exps:\n        return False  # nothing to delete\n    R.delete_exp(experiment_id=exps[name].id)\n    return True","typeGuard":null,"tryCatchPattern":"try:\n    R.delete_exp(experiment_name=name)\nexcept ValueError as e:\n    msg = str(getattr(e.__cause__, 'message', e.__cause__) or e)\n    if 'not exist' in msg.lower() or 'not found' in msg.lower():\n        pass  # already gone; idempotent cleanup\n    else:\n        raise","preventionTips":["Delete by experiment_id obtained from list_experiments(), not by typed name","Make cleanup scripts idempotent by treating 'not found' as success","Keep tracking uri consistent between creation and deletion scripts"],"tags":["qlib","mlflow","experiment-tracking","cleanup"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}