Repository: great-expectations/great_expectations

Issue:
Request for more-informative error message when get_validator() with parameters of incorrect type
This is a small ergonomics-related request that I just wanted to log. When calling `context.get_validator()`, and I pass in an incorrect parameter type (such as `str` for `expectation_suite`), the error message currently gives. 

`AttributeError`: 'str' object has no attribute 'execution_engine_type'

![Screen Shot 2021-01-26 at 5 40 15 PM](https://user-images.githubusercontent.com/25670697/105930392-725d9680-5ffe-11eb-91d4-4eca64998741.png)

**Proposed Solution**
A more informative error message like:

Error : "get_validator was given an expectation_suite "my_suite" which is of type 'str'. It is expecting a object of type ExpectationSuite. Please check your configuration"



Discussion:

Resolving patch:
diff --git a/great_expectations/validator/validator.py b/great_expectations/validator/validator.py
--- a/great_expectations/validator/validator.py
+++ b/great_expectations/validator/validator.py
@@ -32,6 +32,7 @@
     GreatExpectationsError,
     InvalidExpectationConfigurationError,
 )
+from great_expectations.execution_engine import ExecutionEngine
 from great_expectations.expectations.registry import (
     get_expectation_impl,
     get_metric_provider,
@@ -491,7 +492,9 @@ def _resolve_metrics(
         )
 
     def _initialize_expectations(
-        self, expectation_suite=None, expectation_suite_name=None
+        self,
+        expectation_suite: ExpectationSuite = None,
+        expectation_suite_name: str = None,
     ):
         """Instantiates `_expectation_suite` as empty by default or with a specified expectation `config`.
         In addition, this always sets the `default_expectation_args` to:
@@ -515,6 +518,14 @@ def _initialize_expectations(
         Returns:
             None
         """
+        # Checking type of expectation_suite.
+        # Check for expectation_suite_name is already done by ExpectationSuiteIdentifier
+        if expectation_suite and not isinstance(expectation_suite, ExpectationSuite):
+            raise TypeError(
+                "expectation_suite must be of type ExpectationSuite, not {}".format(
+                    type(expectation_suite)
+                )
+            )
         if expectation_suite is not None:
             if isinstance(expectation_suite, dict):
                 expectation_suite = expectationSuiteSchema.load(expectation_suite)


Test patch:
diff --git a/tests/data_context/test_data_context_datasource_sql_methods.py b/tests/data_context/test_data_context_datasource_sql_methods.py
--- a/tests/data_context/test_data_context_datasource_sql_methods.py
+++ b/tests/data_context/test_data_context_datasource_sql_methods.py
@@ -325,7 +325,7 @@ def test_get_validator_expectation_suite_options(
         )
 
     # Failed specification: incorrectly typed expectation suite
-    with pytest.raises(ValidationError):
+    with pytest.raises(TypeError):
         context.get_validator(
             datasource_name="my_sqlite_db",
             data_connector_name="daily",
diff --git a/tests/validator/test_validator.py b/tests/validator/test_validator.py
--- a/tests/validator/test_validator.py
+++ b/tests/validator/test_validator.py
@@ -1,4 +1,5 @@
 import pandas as pd
+import pytest
 
 import great_expectations.expectations.metrics
 from great_expectations.core import IDDict
@@ -7,6 +8,7 @@
 from great_expectations.core.expectation_validation_result import (
     ExpectationValidationResult,
 )
+from great_expectations.exceptions import InvalidDataContextKeyError
 from great_expectations.exceptions.metric_exceptions import MetricProviderError
 from great_expectations.execution_engine import PandasExecutionEngine
 from great_expectations.expectations.core import ExpectColumnMaxToBeBetween
@@ -358,3 +360,23 @@ def test_validator_default_expectation_args__sql(
     )
 
     print(my_validator.get_default_expectation_arguments())
+
+    with pytest.raises(InvalidDataContextKeyError):
+        # expectation_suite_name is a number not str
+        my_validator = context.get_validator(
+            datasource_name="my_sqlite_db",
+            data_connector_name="daily",
+            data_asset_name="table_partitioned_by_date_column__A",
+            partition_identifiers={"date": "2020-01-15"},
+            expectation_suite_name=1,
+        )
+
+    with pytest.raises(TypeError):
+        # expectation_suite is a string not an ExpectationSuite
+        my_validator = context.get_validator(
+            datasource_name="my_sqlite_db",
+            data_connector_name="daily",
+            data_asset_name="table_partitioned_by_date_column__A",
+            partition_identifiers={"date": "2020-01-15"},
+            expectation_suite="I_am_not_an_expectation_suite",
+        )