Fix longstanding bug in metadata deepcopy.