Repository: great-expectations/great_expectations

Issue:
Data Asset name is not displayed in slack notification
**Describe the bug**
After running validations as part of a checkpoint the Data asset name shows as `__no_data_asset_name__`  in slack notifications
![image](https://user-images.githubusercontent.com/14918053/134176561-b97466be-e4a7-4f96-9d97-23dae164a564.png)



**To Reproduce**
Steps to reproduce the behavior:
1. Configure checkpoint with slack notification
2. Run checkpoint
3. See slack output


**Expected behavior**
Data asset name should display actual data asset name

**Environment (please complete the following information):**
 - Operating System: Windows
 - Great Expectations 0.13.32
 



Discussion:

Resolving patch:
diff --git a/great_expectations/render/renderer/email_renderer.py b/great_expectations/render/renderer/email_renderer.py
--- a/great_expectations/render/renderer/email_renderer.py
+++ b/great_expectations/render/renderer/email_renderer.py
@@ -30,6 +30,12 @@ def render(self, validation_result=None, data_docs_pages=None, notify_with=None)
                 data_asset_name = validation_result.meta["batch_kwargs"].get(
                     "data_asset_name", "__no_data_asset_name__"
                 )
+            elif "active_batch_definition" in validation_result.meta:
+                data_asset_name = (
+                    validation_result.meta["active_batch_definition"].data_asset_name
+                    if validation_result.meta["active_batch_definition"].data_asset_name
+                    else "__no_data_asset_name__"
+                )
             else:
                 data_asset_name = "__no_data_asset_name__"
 
diff --git a/great_expectations/render/renderer/opsgenie_renderer.py b/great_expectations/render/renderer/opsgenie_renderer.py
--- a/great_expectations/render/renderer/opsgenie_renderer.py
+++ b/great_expectations/render/renderer/opsgenie_renderer.py
@@ -33,6 +33,12 @@ def render(
                 data_asset_name = validation_result.meta["batch_kwargs"].get(
                     "data_asset_name", "__no_data_asset_name__"
                 )
+            elif "active_batch_definition" in validation_result.meta:
+                data_asset_name = (
+                    validation_result.meta["active_batch_definition"].data_asset_name
+                    if validation_result.meta["active_batch_definition"].data_asset_name
+                    else "__no_data_asset_name__"
+                )
             else:
                 data_asset_name = "__no_data_asset_name__"
 
diff --git a/great_expectations/render/renderer/slack_renderer.py b/great_expectations/render/renderer/slack_renderer.py
--- a/great_expectations/render/renderer/slack_renderer.py
+++ b/great_expectations/render/renderer/slack_renderer.py
@@ -46,6 +46,12 @@ def render(
                 data_asset_name = validation_result.meta["batch_kwargs"].get(
                     "data_asset_name", "__no_data_asset_name__"
                 )
+            elif "active_batch_definition" in validation_result.meta:
+                data_asset_name = (
+                    validation_result.meta["active_batch_definition"].data_asset_name
+                    if validation_result.meta["active_batch_definition"].data_asset_name
+                    else "__no_data_asset_name__"
+                )
             else:
                 data_asset_name = "__no_data_asset_name__"
 


Test patch:
diff --git a/tests/render/test_EmailRenderer.py b/tests/render/test_EmailRenderer.py
--- a/tests/render/test_EmailRenderer.py
+++ b/tests/render/test_EmailRenderer.py
@@ -1,3 +1,4 @@
+from great_expectations.core.batch import BatchDefinition, IDDict
 from great_expectations.core.expectation_validation_result import (
     ExpectationSuiteValidationResult,
 )
@@ -62,6 +63,65 @@ def test_EmailRenderer_validation_results_with_datadocs():
     assert rendered_output == expected_output
 
 
+def test_EmailRenderer_checkpoint_validation_results_with_datadocs():
+    batch_definition = BatchDefinition(
+        datasource_name="test_datasource",
+        data_connector_name="test_dataconnector",
+        data_asset_name="test_data_asset",
+        batch_identifiers=IDDict({"id": "my_id"}),
+    )
+
+    validation_result_suite = ExpectationSuiteValidationResult(
+        results=[],
+        success=True,
+        statistics={
+            "evaluated_expectations": 0,
+            "successful_expectations": 0,
+            "unsuccessful_expectations": 0,
+            "success_percent": None,
+        },
+        meta={
+            "great_expectations_version": "v0.8.0__develop",
+            "active_batch_definition": batch_definition,
+            "expectation_suite_name": "default",
+            "run_id": "2019-09-25T060538.829112Z",
+        },
+    )
+
+    rendered_output = EmailRenderer().render(validation_result_suite)
+
+    expected_output = (
+        "default: Success 🎉",
+        '<p><strong>Batch Validation Status</strong>: Success 🎉</p>\n<p><strong>Expectation suite name</strong>: default</p>\n<p><strong>Data asset name</strong>: test_data_asset</p>\n<p><strong>Run ID</strong>: 2019-09-25T060538.829112Z</p>\n<p><strong>Batch ID</strong>: ()</p>\n<p><strong>Summary</strong>: <strong>0</strong> of <strong>0</strong> expectations were met</p><p>Learn <a href="https://docs.greatexpectations.io/en/latest/guides/tutorials/getting_started/set_up_data_docs.html">here</a> how to review validation results in Data Docs</p>',
+    )
+    assert rendered_output == expected_output
+
+    data_docs_pages = {"local_site": "file:///localsite/index.html"}
+    notify_with = ["local_site"]
+    rendered_output = EmailRenderer().render(
+        validation_result_suite, data_docs_pages, notify_with
+    )
+
+    expected_output = (
+        "default: Success 🎉",
+        '<p><strong>Batch Validation Status</strong>: Success 🎉</p>\n<p><strong>Expectation suite name</strong>: default</p>\n<p><strong>Data asset name</strong>: test_data_asset</p>\n<p><strong>Run ID</strong>: 2019-09-25T060538.829112Z</p>\n<p><strong>Batch ID</strong>: ()</p>\n<p><strong>Summary</strong>: <strong>0</strong> of <strong>0</strong> expectations were met</p><p><strong>DataDocs</strong> can be found here: <a href="file:///localsite/index.html">file:///localsite/index.html</a>.</br>(Please copy and paste link into a browser to view)</p><p>Learn <a href="https://docs.greatexpectations.io/en/latest/guides/tutorials/getting_started/set_up_data_docs.html">here</a> how to review validation results in Data Docs</p>',
+    )
+    assert rendered_output == expected_output
+
+    # not configured
+    notify_with = ["fake_site"]
+    rendered_output = EmailRenderer().render(
+        validation_result_suite, data_docs_pages, notify_with
+    )
+
+    expected_output = (
+        "default: Success 🎉",
+        '<p><strong>Batch Validation Status</strong>: Success 🎉</p>\n<p><strong>Expectation suite name</strong>: default</p>\n<p><strong>Data asset name</strong>: test_data_asset</p>\n<p><strong>Run ID</strong>: 2019-09-25T060538.829112Z</p>\n<p><strong>Batch ID</strong>: ()</p>\n<p><strong>Summary</strong>: <strong>0</strong> of <strong>0</strong> expectations were met</p><strong>ERROR</strong>: The email is trying to provide a link to the following DataDocs: `fake_site`, but it is not configured under data_docs_sites in the great_expectations.yml</br><p>Learn <a href="https://docs.greatexpectations.io/en/latest/guides/tutorials/getting_started/set_up_data_docs.html">here</a> how to review validation results in Data Docs</p>',
+    )
+
+    assert rendered_output == expected_output
+
+
 def test_EmailRenderer_get_report_element():
     email_renderer = EmailRenderer()
 
diff --git a/tests/render/test_OpsgenieRenderer.py b/tests/render/test_OpsgenieRenderer.py
--- a/tests/render/test_OpsgenieRenderer.py
+++ b/tests/render/test_OpsgenieRenderer.py
@@ -1,4 +1,7 @@
-from great_expectations.core import ExpectationSuiteValidationResult
+from great_expectations.core.batch import BatchDefinition, IDDict
+from great_expectations.core.expectation_validation_result import (
+    ExpectationSuiteValidationResult,
+)
 from great_expectations.render.renderer import OpsgenieRenderer
 
 
@@ -33,6 +36,37 @@ def test_OpsgenieRenderer_validation_results_success():
     assert rendered_output == expected_output
 
 
+def test_OpsgenieRenderer_checkpoint_validation_results_success():
+    batch_definition = BatchDefinition(
+        datasource_name="test_datasource",
+        data_connector_name="test_dataconnector",
+        data_asset_name="test_data_asset",
+        batch_identifiers=IDDict({"id": "my_id"}),
+    )
+    validation_result_suite = ExpectationSuiteValidationResult(
+        results=[],
+        success=True,
+        statistics={
+            "evaluated_expectations": 0,
+            "successful_expectations": 0,
+            "unsuccessful_expectations": 0,
+            "success_percent": None,
+        },
+        meta={
+            "great_expectations_version": "v0.12.2__develop",
+            "active_batch_definition": batch_definition,
+            "expectation_suite_name": "default",
+            "run_id": "2021-01-01T000000.000000Z",
+        },
+    )
+
+    rendered_output = OpsgenieRenderer().render(validation_result_suite)
+
+    expected_output = "Batch Validation Status: Success 🎉\nExpectation suite name: default\nData asset name: test_data_asset\nRun ID: 2021-01-01T000000.000000Z\nBatch ID: ()\nSummary: 0 of 0 expectations were met"
+
+    assert rendered_output == expected_output
+
+
 def test_OpsgenieRenderer_validation_results_failure():
 
     validation_result_suite = ExpectationSuiteValidationResult(
diff --git a/tests/render/test_SlackRenderer.py b/tests/render/test_SlackRenderer.py
--- a/tests/render/test_SlackRenderer.py
+++ b/tests/render/test_SlackRenderer.py
@@ -1,3 +1,4 @@
+from great_expectations.core.batch import BatchDefinition, IDDict
 from great_expectations.core.expectation_validation_result import (
     ExpectationSuiteValidationResult,
 )
@@ -132,6 +133,135 @@ def test_SlackRenderer_validation_results_with_datadocs():
     assert rendered_output == expected_output
 
 
+def test_SlackRenderer_checkpoint_validation_results_with_datadocs():
+
+    batch_definition = BatchDefinition(
+        datasource_name="test_datasource",
+        data_connector_name="test_dataconnector",
+        data_asset_name="test_data_asset",
+        batch_identifiers=IDDict({"id": "my_id"}),
+    )
+    validation_result_suite = ExpectationSuiteValidationResult(
+        results=[],
+        success=True,
+        statistics={
+            "evaluated_expectations": 0,
+            "successful_expectations": 0,
+            "unsuccessful_expectations": 0,
+            "success_percent": None,
+        },
+        meta={
+            "great_expectations_version": "v0.8.0__develop",
+            "active_batch_definition": batch_definition,
+            "expectation_suite_name": "default",
+            "run_id": "2019-09-25T060538.829112Z",
+        },
+    )
+
+    rendered_output = SlackRenderer().render(validation_result_suite)
+
+    expected_output = {
+        "blocks": [
+            {
+                "type": "section",
+                "text": {
+                    "type": "mrkdwn",
+                    "text": "*Batch Validation Status*: Success :tada:\n*Expectation suite name*: `default`\n*Data asset name*: `test_data_asset`\n*Run ID*: `2019-09-25T060538.829112Z`\n*Batch ID*: `()`\n*Summary*: *0* of *0* expectations were met",
+                },
+            },
+            {"type": "divider"},
+            {
+                "type": "context",
+                "elements": [
+                    {
+                        "type": "mrkdwn",
+                        "text": "Learn how to review validation results in Data Docs: https://docs.greatexpectations.io/en/latest/guides/tutorials/getting_started/set_up_data_docs.html",
+                    }
+                ],
+            },
+        ],
+        "text": "default: Success :tada:",
+    }
+    print(rendered_output)
+    print(expected_output)
+    assert rendered_output == expected_output
+
+    data_docs_pages = {"local_site": "file:///localsite/index.html"}
+    notify_with = ["local_site"]
+    rendered_output = SlackRenderer().render(
+        validation_result_suite, data_docs_pages, notify_with
+    )
+
+    expected_output = {
+        "blocks": [
+            {
+                "type": "section",
+                "text": {
+                    "type": "mrkdwn",
+                    "text": "*Batch Validation Status*: Success :tada:\n*Expectation suite name*: `default`\n*Data asset name*: `test_data_asset`\n*Run ID*: `2019-09-25T060538.829112Z`\n*Batch ID*: `()`\n*Summary*: *0* of *0* expectations were met",
+                },
+            },
+            {
+                "type": "section",
+                "text": {
+                    "type": "mrkdwn",
+                    "text": "*DataDocs* can be found here: `file:///localsite/index.html` \n (Please copy and paste link into a browser to view)\n",
+                },
+            },
+            {"type": "divider"},
+            {
+                "type": "context",
+                "elements": [
+                    {
+                        "type": "mrkdwn",
+                        "text": "Learn how to review validation results in Data Docs: https://docs.greatexpectations.io/en/latest/guides/tutorials/getting_started/set_up_data_docs.html",
+                    }
+                ],
+            },
+        ],
+        "text": "default: Success :tada:",
+    }
+    assert rendered_output == expected_output
+
+    # not configured
+    notify_with = ["fake_site"]
+    rendered_output = SlackRenderer().render(
+        validation_result_suite, data_docs_pages, notify_with
+    )
+
+    expected_output = {
+        "blocks": [
+            {
+                "type": "section",
+                "text": {
+                    "type": "mrkdwn",
+                    "text": "*Batch Validation Status*: Success :tada:\n*Expectation suite name*: `default`\n*Data asset name*: `test_data_asset`\n*Run ID*: `2019-09-25T060538.829112Z`\n*Batch ID*: `()`\n*Summary*: *0* of *0* expectations were met",
+                },
+            },
+            {
+                "type": "section",
+                "text": {
+                    "type": "mrkdwn",
+                    "text": "*ERROR*: Slack is trying to provide a link to the following DataDocs: `fake_site`, but it is not configured under `data_docs_sites` in the `great_expectations.yml`\n",
+                },
+            },
+            {"type": "divider"},
+            {
+                "type": "context",
+                "elements": [
+                    {
+                        "type": "mrkdwn",
+                        "text": "Learn how to review validation results in Data Docs: https://docs.greatexpectations.io/en/latest/guides/tutorials/getting_started/set_up_data_docs.html",
+                    }
+                ],
+            },
+        ],
+        "text": "default: Success :tada:",
+    }
+
+    assert rendered_output == expected_output
+
+
 def test_SlackRenderer_get_report_element():
     slack_renderer = SlackRenderer()