diff --git a/src/snowflake/cli/_plugins/nativeapp/manager.py b/src/snowflake/cli/_plugins/nativeapp/manager.py index cd75c3a025..0bc7ccf604 100644 --- a/src/snowflake/cli/_plugins/nativeapp/manager.py +++ b/src/snowflake/cli/_plugins/nativeapp/manager.py @@ -68,7 +68,6 @@ from snowflake.cli._plugins.stage.manager import StageManager from snowflake.cli._plugins.stage.utils import print_diff_to_console from snowflake.cli.api.console import cli_console as cc -from snowflake.cli.api.constants import DEFAULT_SIZE_LIMIT_MB from snowflake.cli.api.errno import ( DOES_NOT_EXIST_OR_CANNOT_BE_PERFORMED, DOES_NOT_EXIST_OR_NOT_AUTHORIZED, @@ -90,7 +89,7 @@ from snowflake.cli.api.rendering.sql_templates import ( snowflake_sql_jinja_render, ) -from snowflake.cli.api.secure_path import SecurePath +from snowflake.cli.api.secure_path import UNLIMITED, SecurePath from snowflake.cli.api.sql_execution import SqlExecutionMixin from snowflake.connector import DictCursor, ProgrammingError @@ -600,7 +599,7 @@ def _render_script_templates( script_full_path = SecurePath(self.project_root) / relpath try: template_content = script_full_path.read_text( - file_size_limit_mb=DEFAULT_SIZE_LIMIT_MB + file_size_limit_mb=UNLIMITED ) result = render_from_str(template_content, jinja_context) scripts_contents.append(result) diff --git a/src/snowflake/cli/api/rendering/jinja.py b/src/snowflake/cli/api/rendering/jinja.py index c153f6f447..e65bf6ceac 100644 --- a/src/snowflake/cli/api/rendering/jinja.py +++ b/src/snowflake/cli/api/rendering/jinja.py @@ -106,11 +106,6 @@ def jinja_render_from_str(template_content: str, data: Dict[str, Any]) -> str: return _get_jinja_env().from_string(template_content).render(data) -def path_to_jinja_pathlike_str(path: Path) -> str: - # jinja2 template loader user '/' as path separator (even on Windows) - return "/".join(path.parts) - - def jinja_render_from_file( template_path: Path, data: Dict[str, Any], output_file_path: Optional[Path] = None ) -> Optional[str]: @@ -126,9 +121,7 @@ def jinja_render_from_file( None if file path is provided, else returns the rendered string. """ env = _get_jinja_env( - loader=loaders.FileSystemLoader( - path_to_jinja_pathlike_str(template_path.parent) - ) + loader=loaders.FileSystemLoader(template_path.parent.as_posix()) ) loaded_template = env.get_template(template_path.name) rendered_result = loaded_template.render(**data) diff --git a/src/snowflake/cli/api/rendering/sql_templates.py b/src/snowflake/cli/api/rendering/sql_templates.py index cbfd61b1a7..f832417670 100644 --- a/src/snowflake/cli/api/rendering/sql_templates.py +++ b/src/snowflake/cli/api/rendering/sql_templates.py @@ -19,6 +19,7 @@ from click import ClickException from jinja2 import Environment, StrictUndefined, loaders, meta from snowflake.cli.api.cli_global_context import get_cli_context +from snowflake.cli.api.console.console import cli_console from snowflake.cli.api.exceptions import InvalidTemplate from snowflake.cli.api.rendering.jinja import ( CONTEXT_KEY, @@ -65,6 +66,10 @@ def choose_sql_jinja_env_based_on_template_syntax(template_content: str) -> Envi f" and {_SQL_TEMPLATE_START} ... {_SQL_TEMPLATE_END} syntax." ) if has_old_syntax: + cli_console.warning( + f"Warning: {_OLD_SQL_TEMPLATE_START} ... {_OLD_SQL_TEMPLATE_END} syntax is deprecated." + f" Use {_SQL_TEMPLATE_START} ... {_SQL_TEMPLATE_END} syntax instead." + ) return old_syntax_env return new_syntax_env diff --git a/tests/test_sql.py b/tests/test_sql.py index cf7af192af..12169b6115 100644 --- a/tests/test_sql.py +++ b/tests/test_sql.py @@ -11,7 +11,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - from pathlib import Path from tempfile import NamedTemporaryFile, TemporaryDirectory from unittest import mock @@ -333,6 +332,17 @@ def test_rendering_of_sql(mock_execute_query, query, runner): ) +@mock.patch("snowflake.cli._plugins.sql.commands.SqlManager._execute_string") +def test_old_template_syntax_causes_warning(mock_execute_query, runner): + result = runner.invoke(["sql", "-q", "select &{ aaa }", "-D", "aaa=foo"]) + assert result.exit_code == 0 + assert ( + "Warning: &{ ... } syntax is deprecated. Use <% ... %> syntax instead." + in result.output + ) + mock_execute_query.assert_called_once_with("select foo", cursor_class=VerboseCursor) + + @mock.patch("snowflake.cli._plugins.sql.commands.SqlManager._execute_string") def test_mixed_template_syntax_error(mock_execute_query, runner): result = runner.invoke(