Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MAINTENANCE] Ensure that DataContextConfig has a consistent shape when args are omitted #9469

Merged
merged 8 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ def retrieve_data_context_config_from_cloud(
cloud_config=cloud_config, uri="data-context-configuration"
)
config = response.json()
config.pop("notebooks", None)
config["fluent_datasources"] = _extract_fluent_datasources(config)
return DataContextConfig(**config)

Expand Down
1 change: 0 additions & 1 deletion great_expectations/data_context/data_context_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class DataContextVariableSchema(str, enum.Enum):
VALIDATION_OPERATORS = "validation_operators"
STORES = "stores"
DATA_DOCS_SITES = "data_docs_sites"
NOTEBOOKS = "notebooks"
CONFIG_VARIABLES_FILE_PATH = "config_variables_file_path"
ANONYMOUS_USAGE_STATISTICS = "anonymous_usage_statistics"
CONCURRENCY = "concurrency"
Expand Down
17 changes: 4 additions & 13 deletions great_expectations/data_context/types/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2290,8 +2290,6 @@ class DataContextConfig(BaseYamlConfig):
validation_operators: list of validation operators configured by this DataContext.
stores (Optional[dict]): single holder for all Stores associated with this DataContext.
data_docs_sites (Optional[dict]): DataDocs sites associated with DataContext.
notebooks (Optional[NotebookConfig]): Configurations for Jupyter Notebooks associated with DataContext, such as
the `suite_edit` Notebook.
config_variables_file_path (Optional[str]): path for config_variables file, if used.
anonymous_usage_statistics (Optional[AnonymizedUsageStatisticsConfig]): configuration for enabling or disabling
anonymous usage statistics for GX.
Expand All @@ -2308,7 +2306,7 @@ class DataContextConfig(BaseYamlConfig):
globally, at the ExpectationSuite or ExpectationValidationResults-level.
"""

def __init__( # noqa: C901, PLR0912, PLR0913, PLR0915
def __init__( # noqa: C901, PLR0912, PLR0913
self,
batch_configs: Optional[Dict] = None,
config_version: Optional[float] = None,
Expand All @@ -2327,7 +2325,6 @@ def __init__( # noqa: C901, PLR0912, PLR0913, PLR0915
plugins_directory: Optional[str] = None,
validation_operators=None,
stores: Optional[Dict] = None,
notebooks: Optional[Any] = None,
data_docs_sites: Optional[Dict] = None,
config_variables_file_path: Optional[str] = None,
anonymous_usage_statistics: Optional[AnonymizedUsageStatisticsConfig] = None,
Expand All @@ -2337,9 +2334,6 @@ def __init__( # noqa: C901, PLR0912, PLR0913, PLR0915
progress_bars: Optional[ProgressBarsConfig] = None,
include_rendered_content: Optional[IncludeRenderedContentConfig] = None,
) -> None:
if notebooks:
warnings.warn("The `notebooks` parameter no longer supported.", UserWarning)

# Set defaults
if config_version is None:
config_version = DataContextConfigDefaults.DEFAULT_CONFIG_VERSION.value
Expand Down Expand Up @@ -2373,13 +2367,10 @@ def __init__( # noqa: C901, PLR0912, PLR0913, PLR0915
self.expectations_store_name = expectations_store_name
self.validations_store_name = validations_store_name
self.evaluation_parameter_store_name = evaluation_parameter_store_name
if checkpoint_store_name is not None:
self.checkpoint_store_name = checkpoint_store_name
if profiler_store_name is not None:
self.profiler_store_name = profiler_store_name
self.checkpoint_store_name = checkpoint_store_name
self.profiler_store_name = profiler_store_name
self.plugins_directory = plugins_directory
if validation_operators is not None:
self.validation_operators = validation_operators
Comment on lines -2376 to -2382
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These feel bad. I shouldn't have the reason about whether or not an object has an attr. Shape should be consistent (even if values are not!)

self.validation_operators = validation_operators
self.stores = stores or {}
self.data_docs_sites = data_docs_sites
self.config_variables_file_path = config_variables_file_path
Expand Down
6 changes: 6 additions & 0 deletions tests/data_context/migrator/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def empty_serialized_configuration_bundle() -> dict:
"data_context_id": "27517569-1500-4127-af68-b5bad960a492",
"checkpoints": [],
"data_context_variables": {
"checkpoint_store_name": None,
"config_variables_file_path": None,
"config_version": 3.0,
"data_docs_sites": None,
Expand All @@ -194,7 +195,9 @@ def empty_serialized_configuration_bundle() -> dict:
"globally": False,
},
"plugins_directory": None,
"profiler_store_name": None,
"stores": {},
"validation_operators": None,
"validations_store_name": None,
},
"datasources": [],
Expand Down Expand Up @@ -226,13 +229,16 @@ def serialized_configuration_bundle() -> dict:
"data_docs_sites": None,
"evaluation_parameter_store_name": None,
"expectations_store_name": None,
"checkpoint_store_name": None,
"profiler_store_name": None,
"include_rendered_content": {
"expectation_suite": False,
"expectation_validation_result": False,
"globally": False,
},
"plugins_directory": None,
"stores": {},
"validation_operators": None,
"validations_store_name": None,
},
"datasources": [
Expand Down
1 change: 1 addition & 0 deletions tests/data_context/store/test_data_context_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def test_serialize_cloud_mode(basic_data_context_config: DataContextConfig):
"expectation_validation_result": False,
"globally": False,
},
"profiler_store_name": None,
"plugins_directory": "plugins/",
"stores": {
"evaluation_parameter_store": {
Expand Down
2 changes: 2 additions & 0 deletions tests/data_context/store/test_store_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,8 +1359,10 @@ def test_InlineStoreBackend(empty_data_context) -> None:
("fluent_datasources",),
("include_rendered_content",),
("plugins_directory",),
("profiler_store_name",),
("progress_bars",),
("stores",),
("validation_operators",),
("validations_store_name",),
]

Expand Down
36 changes: 36 additions & 0 deletions tests/data_context/test_data_context_config_ui.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import copy
import os
from typing import Dict, Final, Optional
from unittest import mock

import pytest

Expand Down Expand Up @@ -1560,3 +1561,38 @@ def test_DataContextConfig_with_InMemoryStoreBackendDefaults(
),
DataContextConfig,
)


@pytest.mark.unit
def test_data_context_config_defaults():
config = DataContextConfig()
assert config.to_json_dict() == {
"anonymous_usage_statistics": {
"data_context_id": mock.ANY,
"enabled": True,
"explicit_id": False,
"explicit_url": False,
"usage_statistics_url": "https://stats.greatexpectations.io/great_expectations/v1/usage_statistics",
},
"batch_configs": {},
"checkpoint_store_name": None,
"concurrency": None,
"config_variables_file_path": None,
"config_version": 3,
"data_docs_sites": None,
"datasources": {},
"evaluation_parameter_store_name": None,
"expectations_store_name": None,
"fluent_datasources": {},
"include_rendered_content": {
"expectation_suite": False,
"expectation_validation_result": False,
"globally": False,
},
"plugins_directory": None,
"profiler_store_name": None,
"progress_bars": None,
"stores": {},
"validation_operators": None,
"validations_store_name": None,
}
36 changes: 26 additions & 10 deletions tests/data_context/test_data_context_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def data_context_config_dict() -> dict:
"validations_store_name": "validations_store",
"expectations_store_name": "expectations_store",
"checkpoint_store_name": "checkpoint_store",
"profiler_store_name": "profiler_store",
"config_variables_file_path": "uncommitted/config_variables.yml",
"stores": {
"expectations_store": {
Expand Down Expand Up @@ -455,16 +456,31 @@ def test_data_context_variables_save_config(

cloud_data_context_variables.save_config()

expected_config_dict: dict = {}
for attr in (
"config_variables_file_path",
"config_version",
"data_docs_sites",
"plugins_directory",
"stores",
"include_rendered_content",
):
expected_config_dict[attr] = data_context_config_dict[attr]
expected_config_dict = {
"config_variables_file_path": "uncommitted/config_variables.yml",
"config_version": 3.0,
"data_docs_sites": {},
"plugins_directory": "plugins/",
"stores": {
"expectations_store": {
"class_name": "ExpectationsStore",
"store_backend": {
"class_name": "TupleFilesystemStoreBackend",
"base_directory": "expectations/",
},
},
"evaluation_parameter_store": {
"module_name": "great_expectations.data_context.store",
"class_name": "EvaluationParameterStore",
},
},
"include_rendered_content": {
"expectation_suite": False,
"expectation_validation_result": False,
"globally": False,
},
"profiler_store_name": "profiler_store",
}

assert mock_put.call_count == 1
mock_put.assert_called_with(
Expand Down