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