Added filtering of sorting columns that are not actual database fields (e.x. fullname)
Review Request #9497 — Created Jan. 19, 2018 and discarded — Latest diff uploaded
This fixes a crash throwing a FieldError in DataGrid. The crash is caused by specifying a sort column in the url that is a method (rather than a field; For example "fullname" is a method on User (as
get_full_name()
) and no table column for this field actually exists). The method is resolved from the field name, and added to the queryset's orderby call, which eventually returns with a FieldError (since no column calledget_full_name
exists).DataGrid now ignores these columns and logs a warning to the console (just like it does when sorting by non-existing columns).
Did manual testing on a mock database with various sort columns.
Removed a unit test that no longer was relevant (since it tested the behaviour of
get_sort_column
on these invalid columns, and it no longer gets called).
Added a (passing) unit test that makes sure no exception is thrown and a warning is printed about trying to sort the grid by a column that isn't in the db table.