Skip to content

Commit

Permalink
fix(api): invert filter condition with Unicode (#35)
Browse files Browse the repository at this point in the history
So that it will fallback to == most of the time and ilike when
just Unicode
  • Loading branch information
mvergez authored and amandine-sahl committed Dec 8, 2023
1 parent d0588ac commit 93d6641
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions backend/gn_module_monitoring/monitoring/queries.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask_sqlalchemy import BaseQuery
from sqlalchemy import Integer, and_
from sqlalchemy import Unicode, and_
from werkzeug.datastructures import MultiDict


Expand All @@ -21,10 +21,10 @@ def filter_by_params(self, params: MultiDict = None):
and_list = []
for key, value in params.items():
column = getattr(model, key)
if isinstance(column.type, Integer):
and_list.append(column == value)
else:
if isinstance(column.type, Unicode):
and_list.append(column.ilike(f"%{value}%"))
else:
and_list.append(column == value)
and_query = and_(*and_list)
return self.filter(and_query)

Expand Down

0 comments on commit 93d6641

Please sign in to comment.