From b84f94590974b90a6ef3c49fc9d368dcbd1c6529 Mon Sep 17 00:00:00 2001 From: Ahmed Awan Date: Thu, 14 Mar 2024 15:19:24 -0500 Subject: [PATCH 1/2] [23.1] Handle missing indexer for a dataset In case a dataset does not have an indexer, raise an exception. Fixes the bug mentioned in https://github.com/galaxyproject/galaxy/pull/17639#issuecomment-1995990448 --- lib/galaxy/webapps/galaxy/services/datasets.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/galaxy/webapps/galaxy/services/datasets.py b/lib/galaxy/webapps/galaxy/services/datasets.py index 0d1667a505d5..d08fb1a7f33d 100644 --- a/lib/galaxy/webapps/galaxy/services/datasets.py +++ b/lib/galaxy/webapps/galaxy/services/datasets.py @@ -868,7 +868,7 @@ def _data( # Coverage mode uses index data. if mode == "Coverage": # Get summary using minimal cutoffs. - indexer = self.data_provider_registry.get_data_provider(trans, original_dataset=dataset, source="index") + indexer = self._get_indexer(trans, dataset) return indexer.get_data(chrom, low, high, **kwargs) # TODO: @@ -878,7 +878,7 @@ def _data( # If mode is Auto, need to determine what type of data to return. if mode == "Auto": # Get stats from indexer. - indexer = self.data_provider_registry.get_data_provider(trans, original_dataset=dataset, source="index") + indexer = self._get_indexer(trans, dataset) stats = indexer.get_data(chrom, low, high, stats=True) # If stats were requested, return them. @@ -929,7 +929,7 @@ def _data( # Get mean depth. if not indexer: - indexer = self.data_provider_registry.get_data_provider(trans, original_dataset=dataset, source="index") + indexer = self._get_indexer(trans, dataset) stats = indexer.get_data(chrom, low, high, stats=True) mean_depth = stats["data"]["mean"] @@ -981,3 +981,12 @@ def _raw_data( data = data_provider.get_data(**kwargs) return data + + def _get_indexer(self, trans, dataset): + try: + indexer = self.data_provider_registry.get_data_provider(trans, original_dataset=dataset, source="index") + if indexer is None: + raise Exception("No indexer available for this dataset") + return indexer + except Exception as e: + raise galaxy_exceptions.ObjectNotFound(f"Error getting indexer: {util.unicodify(e)}") From d6914b73879c9096251e74181e87aa1a80ea9af4 Mon Sep 17 00:00:00 2001 From: Ahmed Awan Date: Fri, 15 Mar 2024 15:55:10 -0500 Subject: [PATCH 2/2] exception without the `try/catch` block Also, improve clarity a bit... --- lib/galaxy/webapps/galaxy/services/datasets.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/galaxy/webapps/galaxy/services/datasets.py b/lib/galaxy/webapps/galaxy/services/datasets.py index d08fb1a7f33d..b7a53cd9f917 100644 --- a/lib/galaxy/webapps/galaxy/services/datasets.py +++ b/lib/galaxy/webapps/galaxy/services/datasets.py @@ -863,7 +863,6 @@ def _data( extra_info = None mode = kwargs.get("mode", "Auto") - indexer = None # Coverage mode uses index data. if mode == "Coverage": @@ -928,8 +927,7 @@ def _data( ) # Get mean depth. - if not indexer: - indexer = self._get_indexer(trans, dataset) + indexer = self._get_indexer(trans, dataset) stats = indexer.get_data(chrom, low, high, stats=True) mean_depth = stats["data"]["mean"] @@ -983,10 +981,9 @@ def _raw_data( return data def _get_indexer(self, trans, dataset): - try: - indexer = self.data_provider_registry.get_data_provider(trans, original_dataset=dataset, source="index") - if indexer is None: - raise Exception("No indexer available for this dataset") - return indexer - except Exception as e: - raise galaxy_exceptions.ObjectNotFound(f"Error getting indexer: {util.unicodify(e)}") + indexer = self.data_provider_registry.get_data_provider(trans, original_dataset=dataset, source="index") + if indexer is None: + msg = f"No indexer available for dataset {self.encode_id(dataset.id)}" + log.exception(msg) + raise galaxy_exceptions.ObjectNotFound(msg) + return indexer