Skip to content

Commit

Permalink
fix(dbt Cloud): Support syncing a project without a semantic layer (#301
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Vitor-Avila authored Jun 13, 2024
1 parent 8037a11 commit 7ed1b97
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/preset_cli/api/clients/dbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,9 @@ def get_sl_metrics(self, environment_id: int) -> List[MFMetricSchema]:
variables={"environmentId": environment_id},
headers=self.session.headers,
)

# In case the project doesn't have a semantic layer (old versions)
if payload["data"] is None:
return []
metric_schema = MFMetricSchema()
metrics = [metric_schema.load(metric) for metric in payload["data"]["metrics"]]

Expand Down
22 changes: 22 additions & 0 deletions tests/api/clients/dbt_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,28 @@ def test_dbt_client_get_sl_metrics(mocker: MockerFixture) -> None:
]


def test_dbt_client_get_sl_metrics_no_semantic_layer(mocker: MockerFixture) -> None:
"""
Test the ``get_sl_metrics`` method for old dbt projects that don't have a
semantic layer defined yet.
"""
GraphqlClient = mocker.patch("preset_cli.api.clients.dbt.GraphqlClient")
GraphqlClient().execute.return_value = {
"data": None,
"errors": [
{
"message": "Empty semantic manifest was found. Ensure that you have semantic models defined.",
"locations": [{"line": 3, "column": 17}],
"path": ["metrics"],
},
],
}
auth = Auth()
client = DBTClient(auth)

assert client.get_sl_metrics(108380) == []


def test_dbt_client_get_sl_metric_sql(mocker: MockerFixture) -> None:
"""
Test the ``get_sl_metric_sql`` method.
Expand Down

0 comments on commit 7ed1b97

Please sign in to comment.