You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ossie.apache.org by qu...@apache.org on 2026/09/15 05:11:06 UTC

(ossie) branch main updated: fix(dbt): use pydantic v1 .json() in ossie-to-msi (#331)

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

QMalcolm 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 d4609403 fix(dbt): use pydantic v1 .json() in ossie-to-msi (#331)
d4609403 is described below

commit d46094031829e3ebf0e4e6f346bbf03e81bd41a9
Author: Ntokozo Luthuli <48...@users.noreply.github.com>
AuthorDate: Tue Sep 15 07:11:00 2026 +0200

    fix(dbt): use pydantic v1 .json() in ossie-to-msi (#331)
    
    ossie-to-msi crashed on every input with AttributeError, including on our
    own examples/tpcds_semantic_model.yaml. The CLI called .model_dump_json()
    on PydanticSemanticManifest, but that's a pydantic v1 model, so it only
    has .json().
    
    Switched to .json() with the same options, and added a CLI test — nothing
    covered the CLI before, which is why CI stayed green.
    
    Fixes #296
    
    Signed-off-by: Ntokozo Luthuli <nt...@gmail.com>
---
 converters/dbt/src/ossie_dbt/cli.py |  4 ++-
 converters/dbt/tests/test_cli.py    | 61 +++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+), 1 deletion(-)

diff --git a/converters/dbt/src/ossie_dbt/cli.py b/converters/dbt/src/ossie_dbt/cli.py
index faca2687..a4fce8d2 100644
--- a/converters/dbt/src/ossie_dbt/cli.py
+++ b/converters/dbt/src/ossie_dbt/cli.py
@@ -74,7 +74,9 @@ def _cmd_ossie_to_msi(args: argparse.Namespace) -> None:
     document = OssieDocument.model_validate(raw)
     result = OssieToMSIConverter().convert(document)
 
-    output_path.write_text(result.output.model_dump_json(by_alias=True, exclude_none=True, indent=2))
+    # PydanticSemanticManifest subclasses pydantic.v1.BaseModel, whose JSON
+    # serializer is .json(), not the pydantic v2 .model_dump_json().
+    output_path.write_text(result.output.json(by_alias=True, exclude_none=True, indent=2))
     print(f"Written to {output_path}", file=sys.stderr)
 
 
diff --git a/converters/dbt/tests/test_cli.py b/converters/dbt/tests/test_cli.py
new file mode 100644
index 00000000..892e4a9d
--- /dev/null
+++ b/converters/dbt/tests/test_cli.py
@@ -0,0 +1,61 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""End-to-end tests for the ossie-dbt CLI entry point."""
+
+import json
+from pathlib import Path
+
+import pytest
+
+from ossie_dbt import cli
+from tests.helpers import _ossie_dataset, _ossie_doc, _ossie_field, _ossie_metric
+
+
+def _run_cli(argv: list[str], monkeypatch: pytest.MonkeyPatch) -> None:
+    monkeypatch.setattr("sys.argv", ["ossie-dbt", *argv])
+    cli.main()
+
+
+def test_ossie_to_msi_writes_valid_manifest_json(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
+    """ossie-to-msi must serialize the manifest to JSON without crashing.
+
+    Regression test for the CLI calling the pydantic v2 ``.model_dump_json()``
+    on ``PydanticSemanticManifest``, which subclasses ``pydantic.v1.BaseModel``
+    and only exposes ``.json()``. Before the fix this raised ``AttributeError``
+    on every input, including the repository's own example model.
+    """
+    document = _ossie_doc(
+        datasets=[
+            _ossie_dataset(
+                name="orders",
+                fields=[_ossie_field("order_id"), _ossie_field("amount")],
+                primary_key=["order_id"],
+            )
+        ],
+        metrics=[_ossie_metric("total_amount", "SUM(orders.amount)")],
+    )
+    input_path = tmp_path / "model.yaml"
+    output_path = tmp_path / "semantic_manifest.json"
+    input_path.write_text(document.to_ossie_yaml())
+
+    _run_cli(["ossie-to-msi", "-i", str(input_path), "-o", str(output_path)], monkeypatch)
+
+    assert output_path.exists()
+    manifest = json.loads(output_path.read_text())
+    assert "semantic_models" in manifest
+    assert "metrics" in manifest