Repository: great-expectations/great_expectations

Issue:
CLI command "datasource delete" does not delete the datasource
**Describe the bug**
CLI command "datasource delete" does not delete the datasource

**To Reproduce**
Steps to reproduce the behavior:
1. Have a great_expectations.yml with at least one datasource, let's say named "ds1"
2. Terminal: `great_expectations data delete ds1`
3. CLI displays "Datasource deleted successfully", but the datasource config is still in the config file

**Expected behavior**
the datasource's config is removed from the config file

**Environment (please complete the following information):**
 - OS: N/A
 - GE Version: 0.12.1

**Additional context**

![image](https://user-images.githubusercontent.com/80363/92644297-fbff0880-f297-11ea-9a25-3159a9794e22.png)



Discussion:
This was reported by a user - I reproduced and confirmed.
A workaround is to edit the `great_expectations.yml` config file of your project and remove the section of the datasource you are wishing to delete.

Resolving patch:
diff --git a/great_expectations/cli/datasource.py b/great_expectations/cli/datasource.py
--- a/great_expectations/cli/datasource.py
+++ b/great_expectations/cli/datasource.py
@@ -112,15 +112,17 @@ def delete_datasource(directory, datasource):
     except ValueError:
         cli_message(
             "<red>{}</red>".format(
-                "Datasource {} could not be found".format(datasource)
+                "Datasource {} could not be found.".format(datasource)
             )
         )
         sys.exit(1)
-    else:
+    try:
+        context.get_datasource(datasource)
+    except ValueError:
         cli_message("<green>{}</green>".format("Datasource deleted successfully."))
-
-    if context.get_datasource(datasource) is None:
-        cli_message("<red>{}</red>".format("Datasource not deleted"))
+        sys.exit(1)
+    else:
+        cli_message("<red>{}</red>".format("Datasource not deleted."))
         sys.exit(1)
 
 
diff --git a/great_expectations/data_context/data_context.py b/great_expectations/data_context/data_context.py
--- a/great_expectations/data_context/data_context.py
+++ b/great_expectations/data_context/data_context.py
@@ -764,9 +764,11 @@ def delete_datasource(self, datasource_name=None):
         else:
             datasource = self.get_datasource(datasource_name)
             if datasource:
-                # remove key until we have a delete method on project_config
-                # self._project_config_with_variables_substituted.datasources[datasource_name].remove()
-                # del self._project_config["datasources"][datasource_name]
+                # delete datasources project config
+                del self._project_config_with_variables_substituted.datasources[
+                    datasource_name
+                ]
+                del self._project_config.datasources[datasource_name]
                 del self._cached_datasources[datasource_name]
             else:
                 raise ValueError("Datasource {} not found".format(datasource_name))
@@ -2348,6 +2350,14 @@ def add_datasource(self, name, **kwargs):
 
         return new_datasource
 
+    def delete_datasource(self, name, **kwargs):
+        logger.debug("Starting DataContext.delete_datasource for datasource %s" % name)
+
+        delete_datasource = super().delete_datasource(name, **kwargs)
+        self._save_project_config()
+
+        return delete_datasource
+
     @classmethod
     def find_context_root_dir(cls):
         result = None


Test patch: