Fix sort_query support for queries using mappers