Skip to content

Commit 29addc3

Browse files
refactor: [SNOW-1890085] post code review fixes
1 parent d9075b0 commit 29addc3

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@
2929
from snowflake.cli.api.constants import ObjectType
3030
from snowflake.cli.api.feature_flags import FeatureFlag
3131
from snowflake.cli.api.identifiers import FQN
32-
from snowflake.cli.api.output.types import CommandResult, MessageResult, QueryResult
32+
from snowflake.cli.api.output.types import (
33+
CommandResult,
34+
MessageResult,
35+
QueryResult,
36+
SingleQueryResult,
37+
)
3338
from snowflake.cli.api.secure_path import SecurePath
3439

3540
app = SnowTyperFactory(
@@ -129,9 +134,10 @@ def _dbt_execute(
129134
name = ctx.parent.params["name"]
130135
run_async = ctx.parent.params["run_async"]
131136
execute_args = (dbt_command, name, run_async, *dbt_cli_args)
137+
dbt_manager = DBTManager()
132138

133139
if run_async is True:
134-
result = DBTManager().execute(*execute_args)
140+
result = dbt_manager.execute(*execute_args)
135141
return MessageResult(
136142
f"Command submitted. You can check the result with `snow sql -q \"select execution_status from table(information_schema.query_history_by_user()) where query_id in ('{result.sfqid}');\"`"
137143
)
@@ -141,5 +147,6 @@ def _dbt_execute(
141147
TextColumn("[progress.description]{task.description}"),
142148
transient=True,
143149
) as progress:
144-
progress.add_task(description="Executing dbt command...", total=None)
145-
return QueryResult(DBTManager().execute(*execute_args))
150+
progress.add_task(description=f"Executing 'dbt {dbt_command}'", total=None)
151+
result = dbt_manager.execute(*execute_args)
152+
return SingleQueryResult(result)

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ def deploy(
4444
) -> SnowflakeCursor:
4545
dbt_project_path = path / "dbt_project.yml"
4646
if not dbt_project_path.exists():
47-
raise ClickException(f"dbt_project.yml does not exist in provided path.")
47+
raise ClickException(
48+
f"dbt_project.yml does not exist in directory {path.path.absolute()}."
49+
)
4850

4951
if self.exists(name=name) and force is not True:
5052
raise ClickException(
@@ -69,6 +71,6 @@ def deploy(
6971

7072
def execute(self, dbt_command: str, name: str, run_async: bool, *dbt_cli_args):
7173
if dbt_cli_args:
72-
dbt_command = dbt_command + " " + " ".join([arg for arg in dbt_cli_args])
73-
query = f"EXECUTE DBT PROJECT {name} args='{dbt_command.strip()}'"
74+
dbt_command = " ".join([dbt_command, *dbt_cli_args]).strip()
75+
query = f"EXECUTE DBT PROJECT {name} args='{dbt_command}'"
7476
return self.execute_query(query, _exec_async=run_async)

src/snowflake/cli/api/sql_execution.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,18 @@ def _execute_string(
8787

8888
def execute_string(self, query: str, **kwargs) -> Iterable[SnowflakeCursor]:
8989
"""Executes a single SQL query and returns the results"""
90-
return self._execute_string(query, **kwargs)
90+
return self._execute_string(dedent(query), **kwargs)
9191

9292
def execute_query(self, query: str, **kwargs):
9393
"""Executes a single SQL query and returns the last result"""
94-
*_, last_result = list(self.execute_string(dedent(query), **kwargs))
94+
*_, last_result = list(self.execute_string(query, **kwargs))
9595
return last_result
9696

9797
def execute_queries(self, queries: str, **kwargs):
9898
"""Executes multiple SQL queries (passed as one string) and returns the results as a list"""
9999

100100
# Without remove_comments=True, connectors might throw an error if there is a comment at the end of the file
101-
return list(
102-
self.execute_string(dedent(queries), remove_comments=True, **kwargs)
103-
)
101+
return list(self.execute_string(queries, remove_comments=True, **kwargs))
104102

105103

106104
class SqlExecutor(BaseSqlExecutor):

tests/dbt/test_dbt_commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def test_raises_when_dbt_project_is_not_available(
177177
)
178178

179179
assert result.exit_code == 1, result.output
180-
assert "dbt_project.yml does not exist in provided path." in result.output
180+
assert f"dbt_project.yml does not exist in directory" in result.output
181181
assert mock_connect.mocked_ctx.get_query() == ""
182182

183183
def test_raises_when_dbt_project_exists_and_is_not_force(

0 commit comments

Comments
 (0)