Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[23.0] Fix History contents genome_build filter postgresql bug #17384

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions lib/galaxy/managers/genomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -75,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):
Expand All @@ -86,15 +90,21 @@ 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.database_connection) in 23.2
jdavcs marked this conversation as resolved.
Show resolved Hide resolved
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})
3 changes: 2 additions & 1 deletion lib/galaxy/managers/history_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,9 @@ def parse_type_id_list(self, type_id_list_string, sep=","):

def _add_parsers(self):
super()._add_parsers()
database_connection: str = self.app.config.database_connection
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)
Expand Down
Loading