checking if external_id exists before passing it to query