def _assert_sid_is_in_chain(sid, pid):
    if not sid or not pid:
        return
    chain_model = _get_chain_by_pid(pid)
    if not chain_model or not chain_model.sid:
        return
    if chain_model.sid.did != sid:
        raise d1_common.types.exceptions.ServiceFailure(
            0,
            "Attempted to create object in chain with non-matching SID. "
            'existing_sid="{}", new_sid="{}"'.format(chain_model.sid.did, sid),
        )