Factor out common method _raise_duplicate_object

Change-Id: Id8fcf9500120ada22b92c2a709ad07374a543aed