Added check in cosmos for non-existant parent_id

Also added the corresponding test