You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ossie.apache.org by jb...@apache.org on 2026/09/29 11:56:32 UTC
(ossie) branch main updated: fix(thoughtspot): a malformed column or model name should not crash the whole conversion (#482)
This is an automated email from the ASF dual-hosted git repository.
jbonofre pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ossie.git
The following commit(s) were added to refs/heads/main by this push:
new 26fb4498 fix(thoughtspot): a malformed column or model name should not crash the whole conversion (#482)
26fb4498 is described below
commit 26fb4498aa4664ab4b0e9d9561a17337fdeb0e74
Author: Amir Fathi <am...@gmail.com>
AuthorDate: Tue Sep 29 05:56:26 2026 -0600
fix(thoughtspot): a malformed column or model name should not crash the whole conversion (#482)
* fix(thoughtspot): a malformed column or model name should not crash the whole conversion
A columns[] entry with no name key, or one whose name is not a string
(an int, null, or a bool), was read straight into
identifiers.normalise() and raised a bare KeyError or TypeError
instead of the converter's own "never a bare traceback" contract. A
model name of the same wrongly typed shape hit the same TypeError.
Add a shared _column_display_name() check ahead of the read in
convert_field and convert_metric, and the same type check before
convert()'s model name normalise() call. Both now log a WARNING and
skip the malformed object (TS-FIELD-NO-NAME, TS-FIELD-NAME-INVALID,
TS-METRIC-NO-NAME, TS-METRIC-NAME-INVALID, TS-MODEL-NAME-INVALID),
matching the existing TS-KIND-* degrade and continue pattern rather
than aborting the whole document.
Refs #469: the issue also reports wrongly typed values in
aggregation, data_type, formulas[].expr, join on, and db_column_name,
plus the to-tml stash direction (custom_extensions, schema invalid
documents). None of those are touched here.
* fix(thoughtspot): report a falsy-but-present model name the same as a truthy one
model_display_name = model_body.get("name") or "" coerced 0/False/None to
"" before the type check, so those three values fell back to "model"
silently while 42/True correctly logged TS-MODEL-NAME-INVALID. Read the
raw value first and check it for "name" in model_body, so a falsy
non-string is reported the same as a truthy one; a genuinely missing key
or an explicit empty string still falls back silently.
Parametrize the malformed-name test over 42, True, 0, False, None, and
split the old single-case silent-fallback test into one for a missing
key and one for an empty string.
---
.../src/ossie_thoughtspot/tml_to_ossie.py | 65 +++++++++++++++++++++-
converters/thoughtspot/tests/test_tml_to_ossie.py | 57 +++++++++++++++++++
.../thoughtspot/tests/test_tml_to_ossie_fields.py | 60 ++++++++++++++++++++
.../thoughtspot/tests/test_tml_to_ossie_metrics.py | 35 ++++++++++++
4 files changed, 214 insertions(+), 3 deletions(-)
diff --git a/converters/thoughtspot/src/ossie_thoughtspot/tml_to_ossie.py b/converters/thoughtspot/src/ossie_thoughtspot/tml_to_ossie.py
index ad118a63..033d0150 100644
--- a/converters/thoughtspot/src/ossie_thoughtspot/tml_to_ossie.py
+++ b/converters/thoughtspot/src/ossie_thoughtspot/tml_to_ossie.py
@@ -494,6 +494,41 @@ def _resolve_name_collision(
return {**built, "name": candidate}
+def _column_display_name(column: dict, log: IssueLog, *, kind: str) -> str | None:
+ """The `name` a `columns[]` entry must carry to become a field or metric,
+ or `None` if it cannot.
+
+ `column["name"]` used to be read directly in `convert_field`/
+ `convert_metric`, so a `columns[]` entry with no `name` key raised a bare
+ `KeyError`, and one whose `name` was present but not a string (an int,
+ `null`, or a bool) propagated as a bare `TypeError` out of
+ `identifiers.normalise` two calls later, inside
+ `_field_or_metric_identifier`, both breaking stash.py's own
+ "never a bare traceback" contract. Both are now reported and the column
+ skipped, the same graceful degradation every other `TS-{KIND}-*` gap in
+ `convert_field`/`convert_metric` already gets, rather than aborting the
+ whole model over one malformed column.
+ """
+ if "name" not in column:
+ log.add(
+ code=f"TS-{kind.upper()}-NO-NAME",
+ severity=Severity.WARNING,
+ message=f"a column has no 'name'; it cannot become a {kind}",
+ object_ref=f"{kind}:<unnamed>",
+ )
+ return None
+ name = column["name"]
+ if not isinstance(name, str):
+ log.add(
+ code=f"TS-{kind.upper()}-NAME-INVALID",
+ severity=Severity.WARNING,
+ message=f"column name {name!r} is not a string; it cannot become a {kind}",
+ object_ref=f"{kind}:{name!r}",
+ )
+ return None
+ return name
+
+
def _field_or_metric_identifier(
display_name: str,
physical_hint: str | None,
@@ -608,7 +643,9 @@ def convert_field(
if allocator is None:
allocator = identifiers.Allocator()
- display_name = column["name"]
+ display_name = _column_display_name(column, log, kind="field")
+ if display_name is None:
+ return None
object_ref = f"field:{display_name}"
if "column_id" in column:
@@ -972,7 +1009,9 @@ def convert_metric(
if allocator is None:
allocator = identifiers.Allocator()
- display_name = column["name"]
+ display_name = _column_display_name(column, log, kind="metric")
+ if display_name is None:
+ return None
object_ref = f"metric:{display_name}"
aggregation_raw = properties.get("aggregation", "NONE")
@@ -2047,7 +2086,27 @@ def convert(document_set: DocumentSet) -> OssieConversion:
log = IssueLog()
model_body = document_set.model.body
- model_display_name = model_body.get("name") or ""
+ model_name_raw = model_body.get("name")
+ if "name" in model_body and not isinstance(model_name_raw, str):
+ # Same malformed-type hazard as a column `name` (see
+ # `_column_display_name`): the model has no field to skip, so it
+ # falls back the same way an empty name already does, just with a
+ # WARNING naming what was dropped. Checked before the `or ""`
+ # coercion below so a falsy-but-present value (`0`, `False`, `None`)
+ # is reported the same as a truthy one (`42`, `True`): both are an
+ # explicit non-string value, not a missing key.
+ log.add(
+ code="TS-MODEL-NAME-INVALID",
+ severity=Severity.WARNING,
+ message=(
+ f"model name {model_name_raw!r} is not a string; the "
+ f"semantic model is named 'model' instead"
+ ),
+ object_ref=f"model:{model_name_raw!r}",
+ )
+ model_display_name = ""
+ else:
+ model_display_name = model_name_raw or ""
if not model_display_name:
semantic_model_name = "model"
else:
diff --git a/converters/thoughtspot/tests/test_tml_to_ossie.py b/converters/thoughtspot/tests/test_tml_to_ossie.py
index 137965a2..050541a5 100644
--- a/converters/thoughtspot/tests/test_tml_to_ossie.py
+++ b/converters/thoughtspot/tests/test_tml_to_ossie.py
@@ -1104,6 +1104,63 @@ class TestUnnormalisableNamesAreCaughtNotFatal:
assert fields[0]["label"] == "名前"
+class TestModelNameMalformed:
+ """The model-scope sibling of `TestConvertFieldMalformedName` /
+ `TestConvertMetricMalformedName`: a model `name` that is present but not
+ a string (an int, a bool) used to raise a bare `TypeError` out of
+ `identifiers.normalise` inside `convert()` itself, rather than degrading
+ the way an unfoldable (but string) name already does via
+ `TS-MODEL-NAME-UNNORMALISABLE`. See https://github.com/apache/ossie/issues/469.
+
+ The type check reads the raw `name` value before the `or ""` fallback
+ coercion, so a falsy-but-present value (`0`, `False`, `None`) is reported
+ the same as a truthy one (`42`, `True`): both are an explicit non-string
+ value, not a missing key.
+ """
+
+ @pytest.mark.parametrize("bad_name", [42, True, 0, False, None])
+ def test_a_non_string_model_name_falls_back_and_is_reported(self, bad_name):
+ orders = _table("ORDERS", columns=[_column("Amount", "AMOUNT", "DOUBLE")])
+ model = _model(
+ name=bad_name,
+ model_tables=[{"name": "ORDERS"}],
+ columns=[_attribute("Amount", "ORDERS::Amount")],
+ )
+ result = convert(_document_set(model, orders))
+ assert result.model["name"] == "model"
+ assert any(i["code"] == "TS-MODEL-NAME-INVALID" for i in result.issues.as_dicts())
+ # The rest of the model still converts: a malformed model name does
+ # not take the whole document down.
+ assert result.model["datasets"][0]["fields"][0]["name"] == "amount"
+
+ def test_an_empty_string_model_name_falls_back_silently(self):
+ # An explicit empty string is not a malformed value: falls back to
+ # "model" with no TS-MODEL-NAME-INVALID report.
+ orders = _table("ORDERS", columns=[_column("Amount", "AMOUNT", "DOUBLE")])
+ model = _model(
+ name="",
+ model_tables=[{"name": "ORDERS"}],
+ columns=[_attribute("Amount", "ORDERS::Amount")],
+ )
+ result = convert(_document_set(model, orders))
+ assert result.model["name"] == "model"
+ assert not any(i["code"] == "TS-MODEL-NAME-INVALID" for i in result.issues.as_dicts())
+
+ def test_a_missing_model_name_key_falls_back_silently(self):
+ # No `name` key at all (as opposed to an explicit falsy value) is
+ # not a malformed value either: falls back to "model" with no
+ # TS-MODEL-NAME-INVALID report.
+ orders = _table("ORDERS", columns=[_column("Amount", "AMOUNT", "DOUBLE")])
+ model = _model(
+ model_tables=[{"name": "ORDERS"}],
+ columns=[_attribute("Amount", "ORDERS::Amount")],
+ )
+ del model.body["name"]
+ result = convert(_document_set(model, orders))
+ assert result.model["name"] == "model"
+ assert not any(i["code"] == "TS-MODEL-NAME-INVALID" for i in result.issues.as_dicts())
+
+
class TestKeyDerivationEdgeCasesCommitted:
"""Edge cases attacked and confirmed by hand during development, now
committed so the check runs on every future change instead of living
diff --git a/converters/thoughtspot/tests/test_tml_to_ossie_fields.py b/converters/thoughtspot/tests/test_tml_to_ossie_fields.py
index d2f017bd..f39194a1 100644
--- a/converters/thoughtspot/tests/test_tml_to_ossie_fields.py
+++ b/converters/thoughtspot/tests/test_tml_to_ossie_fields.py
@@ -554,6 +554,66 @@ class TestConvertField:
assert "formula_Bad" in issues[0]["message"]
+class TestConvertFieldMalformedName:
+ """A `columns[]` entry with no `name` key, or a `name` that is present but
+ not a string (an int, `null`, or a bool), used to raise a bare `KeyError`
+ or `TypeError` out of `convert_field` instead of the documented
+ `ConversionError`-or-issue contract. Both must degrade the same way every
+ other malformed-column shape in this class already does: an issue and
+ `None`, not a crash. See https://github.com/apache/ossie/issues/469.
+ """
+
+ def _table(self, name):
+ return {"ORDERS": {"name": "ORDERS", "columns": [
+ {"name": "AMOUNT", "db_column_name": "AMOUNT",
+ "db_column_properties": {"data_type": "DOUBLE"}},
+ ]}}.get(name)
+
+ def test_a_column_with_no_name_logs_and_returns_none(self):
+ log = IssueLog()
+ field = convert_field(
+ {"column_id": "ORDERS::AMOUNT", "properties": {"column_type": "ATTRIBUTE"}},
+ {}, self._table, _resolve, log,
+ )
+ assert field is None
+ assert [i["code"] for i in log.as_dicts()] == ["TS-FIELD-NO-NAME"]
+
+ @pytest.mark.parametrize("bad_name", [42, None, True, False, 3.5, ["Amount"]])
+ def test_a_non_string_name_logs_and_returns_none(self, bad_name):
+ log = IssueLog()
+ field = convert_field(
+ {"name": bad_name, "column_id": "ORDERS::AMOUNT",
+ "properties": {"column_type": "ATTRIBUTE"}},
+ {}, self._table, _resolve, log,
+ )
+ assert field is None
+ assert [i["code"] for i in log.as_dicts()] == ["TS-FIELD-NAME-INVALID"]
+
+ def test_a_malformed_name_does_not_reach_identifiers_normalise(self):
+ # The bug was not just an uncaught exception, it was that the raw,
+ # wrongly-typed value reached identifiers.normalise() at all. Confirm
+ # the fix rejects it before that call, not merely after a broader
+ # try/except was added around it.
+ log = IssueLog()
+ field = convert_field(
+ {"name": 0, "column_id": "ORDERS::AMOUNT", "properties": {"column_type": "ATTRIBUTE"}},
+ {}, self._table, _resolve, log,
+ )
+ assert field is None
+ assert log.as_dicts()[0]["code"] == "TS-FIELD-NAME-INVALID"
+
+ def test_a_well_formed_string_name_is_unaffected(self):
+ log = IssueLog()
+ field = convert_field(
+ {"name": "Amount", "column_id": "ORDERS::AMOUNT",
+ "properties": {"column_type": "ATTRIBUTE"}},
+ {}, self._table, _resolve, log,
+ )
+ assert field["name"] == "amount"
+ assert field["label"] == "Amount"
+ assert log.as_dicts() == []
+
+
class TestPhysicalDatatypeLoss:
"""`_physical_datatype`'s two `None` outcomes are not the same kind of
outcome, and only one of them is a loss worth logging — exercised through
diff --git a/converters/thoughtspot/tests/test_tml_to_ossie_metrics.py b/converters/thoughtspot/tests/test_tml_to_ossie_metrics.py
index 2aab25f7..231816d8 100644
--- a/converters/thoughtspot/tests/test_tml_to_ossie_metrics.py
+++ b/converters/thoughtspot/tests/test_tml_to_ossie_metrics.py
@@ -484,6 +484,41 @@ class TestConvertMetric:
assert "field" in issues[0]["message"]
+class TestConvertMetricMalformedName:
+ """The metric-scope half of the same fix as
+ `TestConvertFieldMalformedName` in test_tml_to_ossie_fields.py: a
+ `columns[]` entry with no `name`, or a non-string `name`, used to raise a
+ bare `KeyError`/`TypeError` out of `convert_metric` instead of degrading
+ with an issue. See https://github.com/apache/ossie/issues/469.
+ """
+
+ def _table(self, name):
+ return {"ORDERS": {"name": "ORDERS", "columns": [
+ {"name": "AMOUNT", "db_column_name": "AMOUNT",
+ "db_column_properties": {"data_type": "DOUBLE"}},
+ ]}}.get(name)
+
+ def test_a_column_with_no_name_logs_and_returns_none(self):
+ log = IssueLog()
+ metric = convert_metric(
+ {"column_id": "ORDERS::AMOUNT", "properties": {"column_type": "MEASURE"}},
+ {}, self._table, _resolve, log,
+ )
+ assert metric is None
+ assert [i["code"] for i in log.as_dicts()] == ["TS-METRIC-NO-NAME"]
+
+ @pytest.mark.parametrize("bad_name", [42, None, True, False, 3.5])
+ def test_a_non_string_name_logs_and_returns_none(self, bad_name):
+ log = IssueLog()
+ metric = convert_metric(
+ {"name": bad_name, "column_id": "ORDERS::AMOUNT",
+ "properties": {"column_type": "MEASURE"}},
+ {}, self._table, _resolve, log,
+ )
+ assert metric is None
+ assert [i["code"] for i in log.as_dicts()] == ["TS-METRIC-NAME-INVALID"]
+
+
class TestContainsAggregateCall:
"""Layer (a) + (b) at the unit level: the broadened set, checked at any depth."""