From 260da75a03536ec684a15cb17659dd7f60b6e509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Tue, 5 Nov 2024 09:01:31 +0100 Subject: [PATCH] Fix `sort_column` and `filter_column` can also be `InstrumentedAttribute` --- c2cgeoform/views/abstract_views.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/c2cgeoform/views/abstract_views.py b/c2cgeoform/views/abstract_views.py index 857e54a9..3dc2a01b 100644 --- a/c2cgeoform/views/abstract_views.py +++ b/c2cgeoform/views/abstract_views.py @@ -100,8 +100,18 @@ def __init__( key: Optional[str] = None, label: Optional[str] = None, renderer: Optional[Callable[[T], JSON]] = None, - sort_column: Optional[sqlalchemy.sql.elements.ColumnElement[Any]] = None, - filter_column: Optional[sqlalchemy.sql.elements.ColumnElement[Any]] = None, + sort_column: Optional[ + Union[ + sqlalchemy.sql.elements.ColumnElement[Any], + sqlalchemy.orm.attributes.InstrumentedAttribute[Any], + ] + ] = None, + filter_column: Optional[ + Union[ + sqlalchemy.sql.elements.ColumnElement[Any], + sqlalchemy.orm.attributes.InstrumentedAttribute[Any], + ] + ] = None, visible: bool = True, ): self._attr = _getattr(model, attr) @@ -140,7 +150,12 @@ def sortable(self) -> bool: def filtrable(self) -> bool: return self._filter_column is not None and isinstance(self._filter_column.type, types.String) - def sort_column(self) -> sqlalchemy.sql.expression.ColumnElement[Any]: + def sort_column( + self, + ) -> Union[ + sqlalchemy.sql.expression.ColumnElement[Any], + sqlalchemy.orm.attributes.InstrumentedAttribute[Any], + ]: assert self._sort_column is not None return self._sort_column