Fixed #23226 -- Prevented extra query when checking for object types in query relation lookups in case of QuerySet.