Skip to content

Commit 0996c46

Browse files
feat: [SNOW-1890085] wip: capture success code from server
1 parent 9b3c654 commit 0996c46

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/snowflake/cli/_plugins/dbt/commands.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from typing import Optional
1919

2020
import typer
21+
from click import ClickException
2122
from rich.progress import Progress, SpinnerColumn, TextColumn
2223
from snowflake.cli._plugins.dbt.constants import DBT_COMMANDS
2324
from snowflake.cli._plugins.dbt.manager import DBTManager
@@ -33,7 +34,6 @@
3334
CommandResult,
3435
MessageResult,
3536
QueryResult,
36-
SingleQueryResult,
3737
)
3838
from snowflake.cli.api.secure_path import SecurePath
3939

@@ -148,5 +148,16 @@ def _dbt_execute(
148148
transient=True,
149149
) as progress:
150150
progress.add_task(description=f"Executing 'dbt {dbt_command}'", total=None)
151+
151152
result = dbt_manager.execute(*execute_args)
152-
return SingleQueryResult(result)
153+
columns = [column.name for column in result.description]
154+
success_column_index = columns.index("SUCCESS")
155+
stdout_column_index = columns.index("STDOUT")
156+
is_success, output = [
157+
(row[success_column_index], row[stdout_column_index]) for row in result
158+
][-1]
159+
160+
if is_success is True:
161+
return MessageResult(output)
162+
else:
163+
raise ClickException(output)

src/snowflake/cli/_plugins/dbt/manager.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ def deploy(
6969

7070
return self.execute_query(query)
7171

72-
def execute(self, dbt_command: str, name: str, run_async: bool, *dbt_cli_args):
72+
def execute(
73+
self, dbt_command: str, name: str, run_async: bool, *dbt_cli_args
74+
) -> SnowflakeCursor:
7375
if dbt_cli_args:
7476
dbt_command = " ".join([dbt_command, *dbt_cli_args]).strip()
7577
query = f"EXECUTE DBT PROJECT {name} args='{dbt_command}'"

0 commit comments

Comments
 (0)