Skip to content

Commit

Permalink
[FEATURE] Cloud Persist Assets immediately (#7748)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kilo59 authored Apr 27, 2023
1 parent f8bb7dc commit 64b1a2e
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,9 @@ def _init_project_config(
def _init_variables(self) -> DataContextVariables:
raise NotImplementedError

def _save_project_config(self) -> None:
def _save_project_config(
self, _fds_datasource: FluentDatasource | None = None
) -> None:
"""
Each DataContext will define how its project_config will be saved through its internal 'variables'.
- FileDataContext : Filesystem.
Expand Down
20 changes: 17 additions & 3 deletions great_expectations/data_context/data_context/cloud_data_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
ConfigurationIdentifier,
ExpectationSuiteIdentifier,
)
from great_expectations.datasource.fluent import Datasource as FluentDatasource
from great_expectations.render.renderer.site_builder import SiteBuilder

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -820,11 +821,24 @@ def _persist_suite_with_store(

return expectation_suite

def _save_project_config(self) -> None:
def _save_project_config(
self, _fds_datasource: FluentDatasource | None = None
) -> None:
"""
See parent 'AbstractDataContext._save_project_config()` for more information.
Explicitly override base class implementation to retain legacy behavior.
"""
logger.debug(f"{type(self).__name__}._save_project_config() is a NoOp")
# TODO: this may be adjusted as part of fluent datasources save flow
# 042723 kilo59
# Currently CloudDataContext and FileDataContext diverge in how FDS are persisted.
# FileDataContexts don't use the DatasourceStore at all to save or hydrate FDS configs.
# CloudDataContext does use DatasourceStore in order to make use of the Cloud http clients.
# The intended future state is for a new FluentDatasourceStore that can fully encapsulate
# the different requirements for FDS vs BDS.
# At which time `_save_project_config` will revert to being a no-op operation on the CloudDataContext.
if _fds_datasource:
self._datasource_store.set(key=None, value=_fds_datasource)
else:
logger.debug(
"CloudDataContext._save_project_config() has no `fds_datasource` to update"
)
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def _init_variables(self) -> FileDataContextVariables:
)
return variables

def _save_project_config(self) -> None:
def _save_project_config(self, _fds_datasource=None) -> None:
"""
See parent 'AbstractDataContext._save_project_config()` for more information.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def root_directory(self) -> str:
return self._context_root_directory

@abc.abstractmethod
def _save_project_config(self) -> None:
def _save_project_config(self, _fds_datasource=None) -> None:
"""
See parent 'AbstractDataContext._save_project_config()` for more information.
Explicitly override base class implementation to retain legacy behavior.
Expand Down
2 changes: 1 addition & 1 deletion great_expectations/datasource/fluent/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ def _save_context_project_config(self):
"""Check if a DataContext is available and save the project config."""
if self._data_context:
try:
self._data_context._save_project_config()
self._data_context._save_project_config(self)
except TypeError as type_err:
warnings.warn(str(type_err), GxSerializationWarning)

Expand Down
5 changes: 1 addition & 4 deletions tests/datasource/fluent/test_contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,14 @@ def test_context_add_or_update_datasource(
)
cloud_api_fake.assert_call_count(
f"{GX_CLOUD_MOCK_BASE_URL}/organizations/{FAKE_ORG_ID}/datasources/{datasource.id}?name={datasource.name}",
1,
2,
)

response = requests.get(
f"{GX_CLOUD_MOCK_BASE_URL}/organizations/{FAKE_ORG_ID}/datasources/{datasource.id}"
)
response.raise_for_status()
print(pf(response.json(), depth=4))
pytest.xfail( # TODO: remove this
"Immediate persistance for cloud not implemented"
)
assert response.json()["data"]["attributes"]["datasource_config"].get("assets")


Expand Down
2 changes: 1 addition & 1 deletion tests/datasource/fluent/test_metadatasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def get_datasource(self, datasource_name: str) -> Datasource:
f"'{datasource_name}' not found. Available datasources are {list(self._datasources.keys())}"
) from exc

def _save_project_config(self) -> None:
def _save_project_config(self, _fs_datasource=None) -> None:
...


Expand Down

0 comments on commit 64b1a2e

Please sign in to comment.