Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dbt): Avoid raising an error when syncing specific models #289

Merged
merged 1 commit into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/preset_cli/api/clients/dbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ def get_models(self, job_id: int) -> List[ModelSchema]:
name
description
type
meta
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/preset_cli/cli/superset/sync/dbt/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def get_sl_metric(
sql = output[start:]

models = get_models_from_sql(sql, dialect, model_map)
if len(models) > 1:
if not models or len(models) > 1:
return None
model = models[0]

Expand Down Expand Up @@ -427,7 +427,7 @@ def fetch_sl_metrics(
continue

models = get_models_from_sql(sql, dialect, model_map)
if len(models) > 1:
if not models or len(models) > 1:
continue
model = models[0]

Expand Down
4 changes: 2 additions & 2 deletions src/preset_cli/cli/superset/sync/dbt/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def get_models_from_sql(
sql: str,
dialect: MFSQLEngine,
model_map: Dict[ModelKey, ModelSchema],
) -> List[ModelSchema]:
) -> Optional[List[ModelSchema]]:
"""
Return the model associated with a SQL query.
"""
Expand All @@ -390,7 +390,7 @@ def get_models_from_sql(

for table in sources:
if ModelKey(table.db, table.name) not in model_map:
raise ValueError(f"Unable to find model for SQL source {table}")
return None

return [model_map[ModelKey(table.db, table.name)] for table in sources]

Expand Down
6 changes: 3 additions & 3 deletions tests/cli/superset/sync/dbt/metrics_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,9 +811,9 @@ def test_get_models_from_sql() -> None:
model_map, # type: ignore
) == [{"name": "a"}, {"name": "b"}]

with pytest.raises(ValueError) as excinfo:
get_models_from_sql("SELECT 1 FROM schema.c", MFSQLEngine.BIGQUERY, {})
assert str(excinfo.value) == "Unable to find model for SQL source schema.c"
assert (
get_models_from_sql("SELECT 1 FROM schema.c", MFSQLEngine.BIGQUERY, {}) is None
)


def test_get_superset_metrics_per_model() -> None:
Expand Down
Loading