def remove_dataset_dependants(
        self, dataset: DatasetRecord, version: Optional[str] = None
    ) -> None:
        """
        When we remove dataset, we need to clear its references in other dataset
        dependencies
        """
        dd = self._datasets_dependencies

        q = self._datasets_dependencies_update().where(dd.c.dataset_id == dataset.id)
        if version:
            q = q.where(dd.c.dataset_version_id == dataset.get_version(version).id)

        q = q.values(dataset_id=None, dataset_version_id=None)

        self.db.execute(q)

        When we remove dataset, we need to clear its references in other dataset
        dependencies
        
src/datachain/data_storage/metastore.py