You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2026/07/31 16:07:44 UTC

(superset) 01/01: fix(db2): stop truncating table comments to one character

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

rusackas pushed a commit to branch fix/db2-table-comment-truncation
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 9404d6ec9a306a0f22bf007ac70ad919a0e6df75
Author: Claude Code <no...@anthropic.com>
AuthorDate: Fri Jul 31 09:07:25 2026 -0700

    fix(db2): stop truncating table comments to one character
    
    Db2EngineSpec.get_table_comment indexed into the comment with
    comment[0] because ibm_db_sa used to return table comments as a
    tuple. ibm_db_sa >= 0.4.1 (ibmdb/python-ibmdbsa#135) fixed that
    upstream and now returns a plain string, but Superset's pin
    (ibm-db-sa<=0.4.4, >=0.4.4 in pyproject.toml) already requires that
    fixed version, so comment[0] has quietly been indexing into a string
    and truncating every DB2 table comment to its first character.
    
    Return the comment directly instead of indexing into it.
    
    Co-Authored-By: Claude Sonnet 5 <no...@anthropic.com>
---
 superset/db_engine_specs/db2.py              | 7 +------
 tests/unit_tests/db_engine_specs/test_db2.py | 9 ++++++---
 2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/superset/db_engine_specs/db2.py b/superset/db_engine_specs/db2.py
index 0e24d341513..d9256dd93e4 100644
--- a/superset/db_engine_specs/db2.py
+++ b/superset/db_engine_specs/db2.py
@@ -125,8 +125,6 @@ class Db2EngineSpec(BaseEngineSpec):
         """
         Get comment of table from a given schema
 
-        Ibm Db2 return comments as tuples, so we need to get the first element
-
         :param inspector: SqlAlchemy Inspector instance
         :param table: Table instance
         :return: comment of table
@@ -134,10 +132,7 @@ class Db2EngineSpec(BaseEngineSpec):
         comment = None
         try:
             table_comment = inspector.get_table_comment(table.table, table.schema)
-            comment = table_comment.get("text")
-            return comment[0]
-        except IndexError:
-            return comment
+            return table_comment.get("text")
         except Exception as ex:  # pylint: disable=broad-except
             logger.error("Unexpected error while fetching table comment", exc_info=True)
             logger.exception(ex)
diff --git a/tests/unit_tests/db_engine_specs/test_db2.py b/tests/unit_tests/db_engine_specs/test_db2.py
index 6f469fb7a20..ed5d58971cd 100644
--- a/tests/unit_tests/db_engine_specs/test_db2.py
+++ b/tests/unit_tests/db_engine_specs/test_db2.py
@@ -39,13 +39,16 @@ def test_epoch_to_dttm() -> None:
 def test_get_table_comment(mocker: MockerFixture):
     """
     Test the `get_table_comment` method.
+
+    ibm_db_sa >= 0.4.1 returns the comment as a plain string (fixed in
+    https://github.com/ibmdb/python-ibmdbsa/pull/135), not a tuple as it
+    used to. Indexing into that string with `comment[0]` truncates every
+    DB2 table comment to its first character; this guards against that.
     """
     from superset.db_engine_specs.db2 import Db2EngineSpec
 
     mock_inspector = mocker.MagicMock()
-    mock_inspector.get_table_comment.return_value = {
-        "text": ("This is a table comment",)
-    }
+    mock_inspector.get_table_comment.return_value = {"text": "This is a table comment"}
 
     assert (
         Db2EngineSpec.get_table_comment(mock_inspector, Table("my_table", "my_schema"))