This is an automated email from the ASF dual-hosted git repository.

alexandrusoare pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 0a3a35018ce fix(mcp): changed_on_humanized null in write tool 
responses (generate_dashboard, generate_chart) (#39488)
0a3a35018ce is described below

commit 0a3a35018ce08af0c6ad4b5d084fc70b55a3a84a
Author: Alexandru Soare <[email protected]>
AuthorDate: Wed May 20 14:08:51 2026 +0300

    fix(mcp): changed_on_humanized null in write tool responses 
(generate_dashboard, generate_chart) (#39488)
---
 superset/mcp_service/chart/tool/generate_chart.py          | 14 ++++++++++++++
 superset/mcp_service/dashboard/tool/generate_dashboard.py  | 14 ++++++++++++++
 .../dashboard/tool/test_dashboard_generation.py            |  5 +++--
 3 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/superset/mcp_service/chart/tool/generate_chart.py 
b/superset/mcp_service/chart/tool/generate_chart.py
index e859ab4f88c..45f5d30a17a 100644
--- a/superset/mcp_service/chart/tool/generate_chart.py
+++ b/superset/mcp_service/chart/tool/generate_chart.py
@@ -352,6 +352,20 @@ async def generate_chart(  # noqa: C901
                             "Chart creation failed - no chart ID returned"
                         )
 
+                    # Reload server-generated timestamps (created_on,
+                    # changed_on) so the serializer sees real values.
+                    from superset import db
+
+                    try:
+                        db.session.refresh(chart)
+                    except SQLAlchemyError:
+                        logger.warning(
+                            "Chart %s created but refresh failed; "
+                            "continuing with current values",
+                            chart.id,
+                            exc_info=True,
+                        )
+
                 await ctx.info(
                     "Chart created successfully: chart_id=%s, chart_name=%s"
                     % (
diff --git a/superset/mcp_service/dashboard/tool/generate_dashboard.py 
b/superset/mcp_service/dashboard/tool/generate_dashboard.py
index 31c038e05a7..de23a1a11b5 100644
--- a/superset/mcp_service/dashboard/tool/generate_dashboard.py
+++ b/superset/mcp_service/dashboard/tool/generate_dashboard.py
@@ -335,6 +335,15 @@ def generate_dashboard(  # noqa: C901
 
                 db.session.add(dashboard)
                 db.session.commit()  # pylint: 
disable=consider-using-transaction
+                try:
+                    db.session.refresh(dashboard)
+                except SQLAlchemyError:
+                    logger.warning(
+                        "Dashboard %s created but refresh failed; "
+                        "continuing with current values",
+                        dashboard.id,
+                        exc_info=True,
+                    )
             except SQLAlchemyError as db_err:
                 try:
                     db.session.rollback()  # pylint: 
disable=consider-using-transaction
@@ -405,6 +414,7 @@ def generate_dashboard(  # noqa: C901
 
         # Convert to our response format
         from superset.mcp_service.dashboard.schemas import (
+            _humanize_timestamp,
             serialize_chart_summary,
             serialize_tag_object,
         )
@@ -418,6 +428,10 @@ def generate_dashboard(  # noqa: C901
             published=dashboard.published,
             created_on=dashboard.created_on,
             changed_on=dashboard.changed_on,
+            created_on_humanized=_humanize_timestamp(dashboard.created_on),
+            changed_on_humanized=_humanize_timestamp(dashboard.changed_on),
+            created_by=dashboard.created_by_name or None,
+            changed_by=dashboard.changed_by_name or None,
             uuid=str(dashboard.uuid) if dashboard.uuid else None,
             
url=f"{get_superset_base_url()}/superset/dashboard/{dashboard.id}/",
             chart_count=len(request.chart_ids),
diff --git 
a/tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_generation.py 
b/tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_generation.py
index e5e99f57b5a..b18d6a125bf 100644
--- a/tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_generation.py
+++ b/tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_generation.py
@@ -20,6 +20,7 @@ Unit tests for dashboard generation MCP tools
 """
 
 import logging
+from datetime import datetime
 from importlib import import_module
 from unittest.mock import Mock, patch
 
@@ -117,8 +118,8 @@ def _mock_dashboard(id: int = 1, title: str = "Test 
Dashboard") -> Mock:
     dashboard.slug = f"test-dashboard-{id}"
     dashboard.description = "Test dashboard description"
     dashboard.published = True
-    dashboard.created_on = "2024-01-01"
-    dashboard.changed_on = "2024-01-01"
+    dashboard.created_on = datetime(2024, 1, 1)
+    dashboard.changed_on = datetime(2024, 1, 1)
     dashboard.created_by = Mock()
     dashboard.created_by.username = "test_user"
     dashboard.changed_by = Mock()

Reply via email to