From 071736ec746db854424c29a590ae344e207d6a46 Mon Sep 17 00:00:00 2001 From: Imri Fattal Date: Thu, 1 Aug 2024 18:29:03 +0200 Subject: [PATCH] Fix: Check exp_id in Experiment list Instead of checking with just the length of the experiment list. Check that the exp_id is in the experiment list. Useful when working with an offset or missing entries in the database. --- src/qcodes/dataset/experiment_container.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qcodes/dataset/experiment_container.py b/src/qcodes/dataset/experiment_container.py index 5e50bbb818e..ccee743efe3 100644 --- a/src/qcodes/dataset/experiment_container.py +++ b/src/qcodes/dataset/experiment_container.py @@ -67,10 +67,10 @@ def __init__( self.conn = conn_from_dbpath_or_conn(conn, path_to_db) - max_id = len(get_experiments(self.conn)) + experiments_list = get_experiments(self.conn) if exp_id is not None: - if exp_id not in range(1, max_id+1): + if exp_id not in experiments_list: raise ValueError('No such experiment in the database') self._exp_id = exp_id else: @@ -86,7 +86,7 @@ def __init__( "(name, exp_id, run_counter)") from e log.info(f"creating new experiment in {self.path_to_db}") - + max_id = max(experiments_list, default=0) name = name or f"experiment_{max_id+1}" sample_name = sample_name or "some_sample" self._exp_id = ne(self.conn, name, sample_name, format_string)