Fix duplicate parties in query