File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed
flask_appbuilder/models/sqla Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -199,10 +199,15 @@ def apply_order_by(
199199 column_leaf = get_column_leaf (order_column )
200200 _alias = self .get_alias_mapping (root_relation , aliases_mapping )
201201 _order_column = getattr (_alias , column_leaf )
202- if order_direction == "asc" :
203- query = query .order_by (asc (_order_column ))
204- else :
205- query = query .order_by (desc (_order_column ))
202+ # get the primary key so we can add a tie breaker of the order
203+ # when the order column is not unique it can cause issues with pagination
204+ pk = self .get_pk ()
205+ direction = asc if order_direction == "asc" else desc
206+ order_by_columns = [direction (_order_column )]
207+ if pk :
208+ order_by_columns .append (direction (pk ))
209+ query = query .order_by (* order_by_columns )
210+
206211 return query
207212
208213 def apply_pagination (
You can’t perform that action at this time.
0 commit comments