When copying a query, we copy expressions as they are. If a select alias is referenced in the query, we can only resolve it properly when the select clause stays the same. IMO, we should either resolve aliases immediately or at the very least when we replace the select clause.
This happens when adding a sorter for an entity view attribute that also contains a SUBSELECT fetched attribute. Not sure yet how to handle this. Either we try to avoid the issue by not copying over the order by clause or we try to somehow allow resetting the order by clause. Another, more or less orthogonal option would be to try to resolve the aliases.