title: How to delete a run_id from MLflow
body: <p>I want to permanently delete a <code>run_id</code> from an experiment in <code>MLflow</code></p>
  <p>I am using the following code:</p>
  <pre><code>import mlflow
  from mlflow.entities import ViewType
  _mlflow_tracking_uri = &quot;the mlflow tracking url&quot;
  exp_id_delete = &quot;2&quot;
  mlflow.set_tracking_uri(_mlflow_tracking_uri)
             
  
  client = mlflow.tracking.MlflowClient()
  run_infos = mlflow.list_run_infos(exp_id_delete, run_view_type=ViewType.DELETED_ONLY)
                 
  for r in run_infos:
                      
     client.delete_run(r.run_id)
  </code></pre>
  <p>But I get an error <code>INVALID_PARAMETER_VALUE: The run blabla must be in the 'active' state. Current state is deleted. </code></p>
  <p>Any ideas ?</p>
  <p><em>UPDATE</em></p>
  <p>I tried writing some code with the help of the link that @Alex Ott suggested:</p>
  <pre><code>import mlflow
  from mlflow.entities import ViewType
  from mlflow.store.tracking import DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH
  from mlflow.store.artifact.artifact_repository_registry import get_artifact_repository
  from mlflow.tracking import _get_store
  from mlflow.entities.lifecycle_stage import LifecycleStage
  from mlflow.exceptions import MlflowException
  _mlflow_tracking_uri = &quot;the mlflow tracking url&quot;
  exp_id_delete = &quot;2&quot;
  mlflow.set_tracking_uri(_mlflow_tracking_uri)
  
  
  client = mlflow.tracking.MlflowClient()
  run_infos = mlflow.list_run_infos(exp_id_delete, run_view_type=ViewType.DELETED_ONLY)
  
  for r in run_infos:
        
  
   print(&quot;- run_id: {}, lifecycle_stage: {}&quot;.format(r.run_id, r.lifecycle_stage))
  
   run = backend_store.get_run(r.run_id)
   if run.info.lifecycle_stage != LifecycleStage.DELETED:
        raise MlflowException(
            &quot;Run % is not in `deleted` lifecycle stage. Only runs in &quot;
            &quot;`deleted` lifecycle stage can be deleted.&quot; % r.run_id
                      )
   artifact_repo = get_artifact_repository(run.info.artifact_uri)
   artifact_repo.delete_artifacts()
   backend_store._hard_delete_run(r.run_id)
   print(&quot;Run with ID %s has been permanently deleted.&quot; % str(r.run_id))
  </code></pre>
  <p>But now, even though I get as first message:</p>
  <pre><code> Deleted runs: run_id: 24ac591d1af840cfb703131dbe1f92a9, lifecycle_stage: deleted 
  </code></pre>
  <p>then I get the following error</p>
  <pre><code>mlflow.exceptions.MlflowException: Run '24ac591d1af840cfb703131dbe1f92a9' not found
  </code></pre>
  <p>Any ideas ?</p>