docs: def clone_dataset(dataset_id,**kwargs):
      """
          Get a single dataset, by ID
      """
  
      user_id = int(kwargs.get('user_id'))
  
      if dataset_id is None:
          return None
  
      dataset = db.DBSession.query(Dataset).filter(
              Dataset.id==dataset_id).options(joinedload_all('metadata')).first()
  
      if dataset is None:
          raise HydraError("Dataset %s does not exist."%(dataset_id))
  
      if dataset is not None and dataset.created_by != user_id:
          owner = db.DBSession.query(DatasetOwner).filter(
                                  DatasetOwner.dataset_id==Dataset.id,
                                  DatasetOwner.user_id==user_id).first()
          if owner is None:
              raise PermissionError("User %s is not an owner of dataset %s and therefore cannot clone it."%(user_id, dataset_id))
  
      db.DBSession.expunge(dataset)
  
      make_transient(dataset)
  
      dataset.name = dataset.name + "(Clone)"
      dataset.id = None
      dataset.cr_date = None
  
      #Try to avoid duplicate metadata entries if the entry has been cloned previously
      for m in dataset.metadata:
          if m.key in ("clone_of", "cloned_by"):
              del(m)
  
      cloned_meta = Metadata()
      cloned_meta.key = "clone_of"
      cloned_meta.value  = str(dataset_id)
      dataset.metadata.append(cloned_meta)
      cloned_meta = Metadata()
      cloned_meta.key = "cloned_by"
      cloned_meta.value  = str(user_id)
      dataset.metadata.append(cloned_meta)
  
      dataset.set_hash()
      db.DBSession.add(dataset)
      db.DBSession.flush()
  
      cloned_dataset = db.DBSession.query(Dataset).filter(
              Dataset.id==dataset.id).first()
  
      return cloned_dataset