def add(self, dataset, skip_sources=False):
    "\n        Ensure a dataset is in the index. Add it if not present.\n\n        :param datacube.model.Dataset dataset: dataset to add\n        :param bool skip_sources: don't attempt to index source (use when sources are already indexed)\n        :rtype: datacube.model.Dataset\n        "
    if (not skip_sources):
        for source in dataset.sources.values():
            self.add(source)
    was_inserted = False
    sources_tmp = dataset.type.dataset_reader(dataset.metadata_doc).sources
    dataset.type.dataset_reader(dataset.metadata_doc).sources = {}
    try:
        _LOG.info('Indexing %s', dataset.id)
        with self._db.begin() as transaction:
            try:
                was_inserted = transaction.insert_dataset(dataset.metadata_doc, dataset.id, dataset.type.id)
                for (classifier, source_dataset) in dataset.sources.items():
                    transaction.insert_dataset_source(classifier, dataset.id, source_dataset.id)
                if dataset.local_uri:
                    transaction.ensure_dataset_location(dataset.id, dataset.local_uri)
            except DuplicateRecordError as e:
                _LOG.warning(str(e))
        if (not was_inserted):
            existing = self.get(dataset.id)
            if existing:
                check_doc_unchanged(existing.metadata_doc, jsonify_document(dataset.metadata_doc), 'Dataset {}'.format(dataset.id))
            if dataset.local_uri:
                try:
                    self._db.ensure_dataset_location(dataset.id, dataset.local_uri)
                except DuplicateRecordError as e:
                    _LOG.warning(str(e))
    finally:
        dataset.type.dataset_reader(dataset.metadata_doc).sources = sources_tmp
    return dataset
Ensure a dataset is in the index. Add it if not present.

:param datacube.model.Dataset dataset: dataset to add
:param bool skip_sources: don't attempt to index source (use when sources are already indexed)
:rtype: datacube.model.Dataset
def add(self, dataset, skip_sources=False):
    "\n        Ensure a dataset is in the index. Add it if not present.\n\n        :param datacube.model.Dataset dataset: dataset to add\n        :param bool skip_sources: don't attempt to index source (use when sources are already indexed)\n        :rtype: datacube.model.Dataset\n        "
    if (not skip_sources):
        for source in dataset.sources.values():
            self.add(source)
    was_inserted = False
    sources_tmp = dataset.type.dataset_reader(dataset.metadata_doc).sources
    dataset.type.dataset_reader(dataset.metadata_doc).sources = {}
    try:
        _LOG.info('Indexing %s', dataset.id)
        with self._db.begin() as transaction:
            try:
                was_inserted = transaction.insert_dataset(dataset.metadata_doc, dataset.id, dataset.type.id)
                for (classifier, source_dataset) in dataset.sources.items():
                    transaction.insert_dataset_source(classifier, dataset.id, source_dataset.id)
                if dataset.local_uri:
                    transaction.ensure_dataset_location(dataset.id, dataset.local_uri)
            except DuplicateRecordError as e:
                _LOG.warning(str(e))
        if (not was_inserted):
            existing = self.get(dataset.id)
            if existing:
                check_doc_unchanged(existing.metadata_doc, jsonify_document(dataset.metadata_doc), 'Dataset {}'.format(dataset.id))
            if dataset.local_uri:
                try:
                    self._db.ensure_dataset_location(dataset.id, dataset.local_uri)
                except DuplicateRecordError as e:
                    _LOG.warning(str(e))
    finally:
        dataset.type.dataset_reader(dataset.metadata_doc).sources = sources_tmp
    return dataset