Repository: great-expectations/great_expectations
Pull request #7034 (2023-02-02 16:04:14)

[MAINTENANCE] Update `update_` methods in `DataContext` to return persisted object
Changes proposed in this pull request:
- Some store updates impact the state of the updated object - we should reflect that in our return value.


### Definition of Done
- [x] My code follows the Great Expectations [style guide](https://docs.greatexpectations.io/docs/contributing/style_guides/code_style)
- [x] I have performed a [self-review](https://docs.greatexpectations.io/docs/contributing/contributing_checklist) of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have added [unit tests](https://docs.greatexpectations.io/docs/contributing/contributing_test#writing-unit-and-integration-tests) where applicable and made sure that new and existing tests are passing.
- [x] I have run any local integration tests and made sure that nothing is broken.


netlify[bot]: ### <span aria-hidden="true">👷</span> Deploy Preview for *niobium-lead-7998* processing.


|  Name | Link |
|---------------------------------|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | b84df574e945a9fa9d9c87784d4d29524230ea2f |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/sites/niobium-lead-7998/deploys/63dbdf01c449ee00084d7290 |
codesee-maps[bot]: <details>
<summary><b>👇 <a href="https://app.codesee.io/r/reviews?pr=7034&src=https%3A%2F%2Fgithub.com%2Fgreat-expectations%2Fgreat_expectations">Click on the image</a> for a new way to code review</b>
</summary>

  - Make big changes easier — review code in small groups of related files
  - Know where to start — see the whole change at a glance
  - Take a code tour — explore the change with an interactive tour
  - Make comments and review — all fully sync’ed with github

    [Try it now!](https://app.codesee.io/r/reviews?pr=7034&src=https%3A%2F%2Fgithub.com%2Fgreat-expectations%2Fgreat_expectations)
</details>

[![Review these changes using an interactive CodeSee Map](https://s3.us-east-2.amazonaws.com/maps.codesee.io/images/github/great-expectations/great_expectations/7034/280bec49/b84df574e945a9fa9d9c87784d4d29524230ea2f.svg)](https://app.codesee.io/r/reviews?pr=7034&src=https%3A%2F%2Fgithub.com%2Fgreat-expectations%2Fgreat_expectations)

#### Legend
![CodeSee Map Legend](https://app.codesee.io/Legend_v2.png)

Patch:
diff --git a/great_expectations/data_context/data_context/abstract_data_context.py b/great_expectations/data_context/data_context/abstract_data_context.py
index ea3459b99..c8fba7cd4 100644
--- a/great_expectations/data_context/data_context/abstract_data_context.py
+++ b/great_expectations/data_context/data_context/abstract_data_context.py
@@ -768,7 +768,7 @@ class AbstractDataContext(ConfigPeer, ABC):
         self,
         datasource: Union[LegacyDatasource, BaseDatasource],
         save_changes: bool | None = None,
-    ) -> None:
+    ) -> Datasource:
         """Updates a Datasource that already exists in the store.
 
         Args:
@@ -776,7 +776,7 @@ class AbstractDataContext(ConfigPeer, ABC):
             save_changes: do I save changes to disk?
         """
         save_changes = self._determine_save_changes_flag(save_changes)
-        self._update_datasource(datasource=datasource, save_changes=save_changes)
+        return self._update_datasource(datasource=datasource, save_changes=save_changes)
 
     def _update_datasource(
         self,
@@ -2241,7 +2241,7 @@ class AbstractDataContext(ConfigPeer, ABC):
     def update_expectation_suite(
         self,
         expectation_suite: ExpectationSuite,
-    ) -> None:
+    ) -> ExpectationSuite:
         """Update an ExpectationSuite that already exists.
 
         Args:
@@ -2257,7 +2257,7 @@ class AbstractDataContext(ConfigPeer, ABC):
                 f"expectation_suite with name {expectation_suite_name} does not exist."
             )
 
-        self._add_expectation_suite(
+        return self._add_expectation_suite(
             expectation_suite_name=expectation_suite_name,
             id=expectation_suite.ge_cloud_id,
             expectations=expectation_suite.expectations,
@@ -2493,7 +2493,7 @@ class AbstractDataContext(ConfigPeer, ABC):
             ge_cloud_id=ge_cloud_id,
         )
 
-    def update_profiler(self, profiler: RuleBasedProfiler) -> None:
+    def update_profiler(self, profiler: RuleBasedProfiler) -> RuleBasedProfiler:
         """Update a Profiler that already exists.
 
         Args:
@@ -2502,7 +2502,7 @@ class AbstractDataContext(ConfigPeer, ABC):
         Raises:
             ProfilerNotFoundError: A profiler with the given name/id does not already exist.
         """
-        RuleBasedProfiler.update_profiler(
+        return RuleBasedProfiler.update_profiler(
             profiler=profiler,
             profiler_store=self.profiler_store,
             data_context=self,
diff --git a/great_expectations/rule_based_profiler/rule_based_profiler.py b/great_expectations/rule_based_profiler/rule_based_profiler.py
index cfd9d50a9..8bb4b2302 100644
--- a/great_expectations/rule_based_profiler/rule_based_profiler.py
+++ b/great_expectations/rule_based_profiler/rule_based_profiler.py
@@ -1247,7 +1247,7 @@ class BaseRuleBasedProfiler(ConfigPeer):
         profiler: RuleBasedProfiler,
         profiler_store: ProfilerStore,
         data_context: AbstractDataContext,
-    ) -> None:
+    ) -> RuleBasedProfiler:
         name = profiler.name
         id = profiler.ge_cloud_id
 
@@ -1268,8 +1268,13 @@ class BaseRuleBasedProfiler(ConfigPeer):
         else:
             RuleBasedProfiler.delete_profiler(name=name, profiler_store=profiler_store)
 
-        _ = RuleBasedProfiler.add_profiler(
-            config=profiler.config,
+        config = profiler.config
+        config.config_version = profiler.config_version
+        config.rules = {rule.name: rule.to_dict() for rule in profiler.rules}
+        config.variables = convert_variables_to_dict(profiler.variables)
+
+        return RuleBasedProfiler.add_profiler(
+            config=config,
             data_context=data_context,
             profiler_store=profiler_store,
         )


Test patch:
diff --git a/tests/data_context/test_data_context_state_management.py b/tests/data_context/test_data_context_state_management.py
index fee5ecbb6..466cb62a4 100644
--- a/tests/data_context/test_data_context_state_management.py
+++ b/tests/data_context/test_data_context_state_management.py
@@ -333,8 +333,9 @@ def test_update_expectation_suite_success(
             kwargs={"column": "x", "value_set": [1, 2, 4]},
         ),
     ]
-    context.update_expectation_suite(suite)
+    updated_suite = context.update_expectation_suite(suite)
 
+    assert updated_suite.expectations == suite.expectations
     assert context.expectations_store.save_count == 2
 
 
@@ -348,7 +349,7 @@ def test_update_expectation_suite_failure(
     suite = ExpectationSuite(expectation_suite_name=suite_name)
 
     with pytest.raises(gx_exceptions.DataContextError) as e:
-        context.update_expectation_suite(suite)
+        _ = context.update_expectation_suite(suite)
 
     assert f"expectation_suite with name {suite_name} does not exist." in str(e.value)
 
@@ -443,9 +444,10 @@ def test_update_profiler_success(
 
     assert context.profiler_store.save_count == 1
 
-    profiler.rules = {}
-    context.update_profiler(profiler)
+    profiler.rules = []
+    updated_profiler = context.update_profiler(profiler)
 
+    assert updated_profiler.rules == profiler.rules
     assert context.profiler_store.save_count == 2
 
 
@@ -461,7 +463,7 @@ def test_update_profiler_failure(in_memory_data_context: EphemeralDataContextSpy
     )
 
     with pytest.raises(gx_exceptions.ProfilerNotFoundError) as e:
-        context.update_profiler(profiler)
+        _ = context.update_profiler(profiler)
 
     assert f"Non-existent Profiler configuration named {name}" in str(e.value)