Fix support for session-based ownership of queries