Fixed #23266 -- Prevented queries caused by type checking lookup values

Small modifications done by committer.