Skip to content

Resolve "Backend fails hard when trying to order by field name without using `user_field_names`"

Merge Request Checklist

  • changelog.md has been updated if required
  • Documentation has been updated
  • Quality Standards are met
  • The UI/UX has been updated following UI Style Guide
  • The redoc API pages have been updated for any REST API changes
  • The per database user API docs page has been updated for any REST API changes made to endpoints which can be accessed via a user created token
  • Has performance been considered and tested when appropriate? Ideally Baserow should be performant when working with hundreds of thousands of rows
  • New/Changed Premium features are separated correctly in the premium folder
  • There are tests for and it has been checked that any changed/new django ORM code is sensible, doesn't perform N queries and that table models are not generated needlessly or generated with all columns when only a few are needed.

Closes #565 (closed)

Details

  • Made sure that passing "user_field_names=false" as a query parameter will now correctly use the provided value (i.e. "false") subsequently. For that a the validate_query_params decorator and a new serializer was used/created. Before it would simply check if "user_field_names" was provided as a query parameter regardless of what value was passed. This is needed so that when providing "user_field_names=false" and "order_by=field_XX" it will actually use the field id instead of the names.
  • Wrapped the extraction of the field ID in a try, except block so that the backend won't fail hard. Now when a "name" string is provided while an "id" string is expected it will simply result in an error of "OrderByFieldNotFound" since the name will not get found in the dictionary because the keys of the dictionary will be ints (i.e. field ids).
  • Removed the passing of additional string to "OrderByFieldNotFound" exception since that additional string is not used anywhere.
  • On top of those changes directly related to the bug/issue, I made sure that the "order_by_fields_string" function would correctly account for the "get_order" function of a field type. So when a field_name/id is passed as a query param that fields "get_order" function is being called.
    • Since the "get_order" function expects a "view_sort" model and we can't provide one from the "order_by_fields_string" the "get_order" function was changed, so that it simply expects the "order_direction" as a string. Either "ASC" or "DESC".
Edited by Ghost User

Merge request reports