From 38b11075741f7a4581fc7bea6f9bbc00ced87274 Mon Sep 17 00:00:00 2001 From: Ahmed Awan Date: Mon, 29 Jan 2024 12:43:27 -0600 Subject: [PATCH 1/3] [23.0] Fix History contents `genome_build` filter postgresql bug Check the user's db connection and use appropriate query/function. --- lib/galaxy/managers/genomes.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/galaxy/managers/genomes.py b/lib/galaxy/managers/genomes.py index f6af2d73d9a7..ce67796d34ad 100644 --- a/lib/galaxy/managers/genomes.py +++ b/lib/galaxy/managers/genomes.py @@ -4,7 +4,10 @@ TYPE_CHECKING, ) -from sqlalchemy import func +from sqlalchemy import ( + func, + text, +) from galaxy import model as m from galaxy.exceptions import ( @@ -86,7 +89,11 @@ def _create_genome_filter(model_class=None): # Doesn't filter genome_build for collections if model_class.__name__ == "HistoryDatasetCollectionAssociation": return False - column = func.json_extract(model_class.table.c._metadata, "$.dbkey") + # TODO: should use is_postgres(self.app.config.database_connection) in 23.2 + if self.app.config.database_connection.startswith("postgres"): + column = text("convert_from(metadata, 'UTF8')::json ->> 'dbkey'") + else: + column = func.json_extract(model_class.table.c._metadata, "$.dbkey") lower_val = val.lower() # Ignore case if op == "eq": cond = func.lower(column) == lower_val From 3e94c4d3dbc0152d88f7617b97c73f7b15318020 Mon Sep 17 00:00:00 2001 From: Ahmed Awan Date: Tue, 30 Jan 2024 07:39:42 -0600 Subject: [PATCH 2/3] check dbkey: [".."] as well, fix mypy errors --- lib/galaxy/managers/genomes.py | 11 +++++++---- lib/galaxy/managers/history_contents.py | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/galaxy/managers/genomes.py b/lib/galaxy/managers/genomes.py index ce67796d34ad..74ccdc521933 100644 --- a/lib/galaxy/managers/genomes.py +++ b/lib/galaxy/managers/genomes.py @@ -78,6 +78,7 @@ def _get_index_filename(self, id, tbl_entries, ext, index_type): class GenomeFilterMixin: orm_filter_parsers: "OrmFilterParsersType" + database_connection: str valid_ops = ("eq", "contains", "has") def create_genome_filter(self, attr, op, val): @@ -89,19 +90,21 @@ def _create_genome_filter(model_class=None): # Doesn't filter genome_build for collections if model_class.__name__ == "HistoryDatasetCollectionAssociation": return False - # TODO: should use is_postgres(self.app.config.database_connection) in 23.2 - if self.app.config.database_connection.startswith("postgres"): + # TODO: should use is_postgres(self.database_connection) in 23.2 + if self.database_connection.startswith("postgres"): column = text("convert_from(metadata, 'UTF8')::json ->> 'dbkey'") else: column = func.json_extract(model_class.table.c._metadata, "$.dbkey") lower_val = val.lower() # Ignore case + # dbkey can either be "hg38" or '["hg38"]', so we need to check both if op == "eq": - cond = func.lower(column) == lower_val + cond = func.lower(column) == lower_val or func.lower(column) == f'["{lower_val}"]' else: cond = func.lower(column).contains(lower_val, autoescape=True) return cond return _create_genome_filter - def _add_parsers(self): + def _add_parsers(self, database_connection: str): + self.database_connection = database_connection self.orm_filter_parsers.update({"genome_build": self.create_genome_filter}) diff --git a/lib/galaxy/managers/history_contents.py b/lib/galaxy/managers/history_contents.py index 6acd74bf5a07..bb34925e3639 100644 --- a/lib/galaxy/managers/history_contents.py +++ b/lib/galaxy/managers/history_contents.py @@ -631,9 +631,10 @@ def parse_type_id_list(self, type_id_list_string, sep=","): return [self.decode_type_id(type_id) for type_id in type_id_list_string.split(sep)] def _add_parsers(self): + database_connection: str = self.app.config.database_connection super()._add_parsers() annotatable.AnnotatableFilterMixin._add_parsers(self) - genomes.GenomeFilterMixin._add_parsers(self) + genomes.GenomeFilterMixin._add_parsers(self, database_connection) deletable.PurgableFiltersMixin._add_parsers(self) taggable.TaggableFilterMixin._add_parsers(self) tools.ToolFilterMixin._add_parsers(self) From 5ffa9e153b2e6650c7aa1a9d9672afcfa356b07b Mon Sep 17 00:00:00 2001 From: Ahmed Hamid Awan Date: Tue, 30 Jan 2024 13:57:09 -0600 Subject: [PATCH 3/3] move database_connection assignment after super()... Co-authored-by: John Davis --- lib/galaxy/managers/history_contents.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/galaxy/managers/history_contents.py b/lib/galaxy/managers/history_contents.py index bb34925e3639..6767ebbbfc39 100644 --- a/lib/galaxy/managers/history_contents.py +++ b/lib/galaxy/managers/history_contents.py @@ -631,8 +631,8 @@ def parse_type_id_list(self, type_id_list_string, sep=","): return [self.decode_type_id(type_id) for type_id in type_id_list_string.split(sep)] def _add_parsers(self): - database_connection: str = self.app.config.database_connection super()._add_parsers() + database_connection: str = self.app.config.database_connection annotatable.AnnotatableFilterMixin._add_parsers(self) genomes.GenomeFilterMixin._add_parsers(self, database_connection) deletable.PurgableFiltersMixin._add_parsers(self)