Commit d08aa077 authored by davelopez's avatar davelopez
Browse files

Replace `ilike` with `lower`

parent 59de798d
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -7,7 +7,10 @@ Mixins for Taggable model managers and serializers.
import logging
from typing import Type

from sqlalchemy import sql
from sqlalchemy import (
    func,
    sql,
)

from galaxy import model
from galaxy.model.tags import GalaxyTagHandler
@@ -118,15 +121,16 @@ class TaggableFilterMixin:
            target_model = getattr(model, f"{class_name}TagAssociation")
            id_column = f"{target_model.table.name.rsplit('_tag_association')[0]}_id"
            column = target_model.table.c.user_tname + ":" + target_model.table.c.user_value
            lower_val = val.lower()  # Ignore case
            if op == "eq":
                if ":" not in val:
                if ":" not in lower_val:
                    # We require an exact match and the tag to look for has no user_value,
                    # so we can't just concatenate user_tname, ':' and user_vale
                    cond = target_model.table.c.user_tname.ilike(val)
                    cond = func.lower(target_model.table.c.user_tname) == lower_val
                else:
                    cond = column.ilike(val)
                    cond = func.lower(column) == lower_val
            else:
                cond = column.contains(val, autoescape=True)
                cond = func.lower(column).contains(lower_val, autoescape=True)
            return sql.expression.and_(model_class.table.c.id == getattr(target_model.table.c, id_column), cond)

        return _create_tag_filter