Skip to content

Commit

Permalink
More updates according to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-melnacouzi committed Jul 19, 2024
1 parent 5a75587 commit e3249ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 15 additions & 6 deletions src/snowflake/cli/plugins/nativeapp/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from functools import cached_property
from pathlib import Path
from textwrap import dedent
from typing import List, Optional, TypedDict
from typing import Any, List, Optional, TypedDict

import jinja2
from click import ClickException
Expand Down Expand Up @@ -562,14 +562,23 @@ def create_app_package(self) -> None:
)

def _expand_script_templates(
self, env: jinja2.Environment, jinja_context, scripts: List[str]
):
queued_queries = []
self, env: jinja2.Environment, jinja_context: dict[str, Any], scripts: List[str]
) -> List[str]:
"""
Input:
- env: Jinja2 environment
- jinja_context: a dictionary with the jinja context
- scripts: list of scripts that need to be expanded with Jinja
Returns:
- List of expanded scripts content.
Size of the return list is the same as the size of the input scripts list.
"""
scripts_contents = []
for relpath in scripts:
try:
template = env.get_template(relpath)
result = template.render(**jinja_context)
queued_queries.append(result)
scripts_contents.append(result)

except jinja2.TemplateNotFound as e:
raise MissingScriptError(e.name) from e
Expand All @@ -580,7 +589,7 @@ def _expand_script_templates(
except jinja2.UndefinedError as e:
raise InvalidScriptError(relpath, e) from e

return queued_queries
return scripts_contents

def _apply_package_scripts(self) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion src/snowflake/cli/plugins/nativeapp/run_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def _execute_sql_script(
If database_name is passed in, it will be used first.
"""
try:
if database_name:
if database_name is not None:
self._execute_query(f"use database {database_name}")

self._execute_queries(script_content)
Expand Down

0 comments on commit e3249ab

Please sign in to comment.