@@ -273,8 +273,8 @@ async def _search(
273273
274274 stmt = select (* columns )
275275
276- stmt = apply_search_filters (table .__table__ . columns . __getitem__ , stmt , search )
277- stmt = apply_sort_constraints (table .__table__ . columns . __getitem__ , stmt , sorts )
276+ stmt = apply_search_filters (table .__table__ , stmt , search )
277+ stmt = apply_sort_constraints (table .__table__ , stmt , sorts )
278278
279279 if distinct :
280280 stmt = stmt .distinct ()
@@ -314,7 +314,7 @@ async def _summary(
314314 count_col = pk_columns [0 ]
315315
316316 stmt = select (* columns , func .count (count_col ).label ("count" ))
317- stmt = apply_search_filters (table .__table__ . columns . __getitem__ , stmt , search )
317+ stmt = apply_search_filters (table .__table__ , stmt , search )
318318 stmt = stmt .group_by (* columns )
319319
320320 # Execute the query
@@ -453,10 +453,10 @@ def _build_datetime_range_multi_expr(
453453 )
454454
455455
456- def apply_search_filters (column_mapping , stmt , search ):
456+ def apply_search_filters (table , stmt , search ):
457457 for query in search :
458458 try :
459- column = column_mapping ( query ["parameter" ])
459+ column = table . columns [ query ["parameter" ]]
460460 except KeyError as e :
461461 raise InvalidQueryError (f"Unknown column { query ['parameter' ]} " ) from e
462462
@@ -525,11 +525,11 @@ def apply_search_filters(column_mapping, stmt, search):
525525 return stmt
526526
527527
528- def apply_sort_constraints (column_mapping , stmt , sorts ):
528+ def apply_sort_constraints (table , stmt , sorts ):
529529 sort_columns = []
530530 for sort in sorts or []:
531531 try :
532- column = column_mapping ( sort ["parameter" ])
532+ column = table . columns [ sort ["parameter" ]]
533533 except KeyError as e :
534534 raise InvalidQueryError (
535535 f"Cannot sort by { sort ['parameter' ]} : unknown column"
0 commit comments