Do a server-side sort if there is a primary key. Fix a couple of tests that were failing due to the new sorting. ticket 794