From dae4e10f3eb0e896dbb4eacef0d0774fea410719 Mon Sep 17 00:00:00 2001 From: Adam Stus Date: Mon, 16 Dec 2024 16:04:11 +0100 Subject: [PATCH] Moved default streamlit warehouse from model (#1952) --- RELEASE-NOTES.md | 1 + .../cli/_plugins/streamlit/manager.py | 9 ++++- .../project/schemas/v1/streamlit/streamlit.py | 2 +- tests/api/utils/test_definition_rendering.py | 1 - tests/streamlit/test_streamlit_manager.py | 38 +++++++++++++++++++ 5 files changed, 48 insertions(+), 3 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index f158788b7c..81bd32d667 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -17,6 +17,7 @@ ## Backward incompatibility ## Deprecations +* Added deprecation message for default Streamlit warehouse ## New additions * Add Release Directives support by introducing the following commands: diff --git a/src/snowflake/cli/_plugins/streamlit/manager.py b/src/snowflake/cli/_plugins/streamlit/manager.py index 3eabd528d9..8d51c9f240 100644 --- a/src/snowflake/cli/_plugins/streamlit/manager.py +++ b/src/snowflake/cli/_plugins/streamlit/manager.py @@ -104,8 +104,15 @@ def _create_streamlit( query.append(f"MAIN_FILE = '{streamlit.main_file}'") if streamlit.imports: query.append(streamlit.get_imports_sql()) - if streamlit.query_warehouse: + + if not streamlit.query_warehouse: + cli_console.warning( + "[Deprecation] In next major version we will remove default query_warehouse='streamlit'." + ) + query.append(f"QUERY_WAREHOUSE = 'streamlit'") + else: query.append(f"QUERY_WAREHOUSE = {streamlit.query_warehouse}") + if streamlit.title: query.append(f"TITLE = '{streamlit.title}'") diff --git a/src/snowflake/cli/api/project/schemas/v1/streamlit/streamlit.py b/src/snowflake/cli/api/project/schemas/v1/streamlit/streamlit.py index c7a454d077..c77ce9e00d 100644 --- a/src/snowflake/cli/api/project/schemas/v1/streamlit/streamlit.py +++ b/src/snowflake/cli/api/project/schemas/v1/streamlit/streamlit.py @@ -27,7 +27,7 @@ class Streamlit(UpdatableModel, ObjectIdentifierModel(object_name="Streamlit")): title="Stage in which the app’s artifacts will be stored", default="streamlit" ) query_warehouse: str = Field( - title="Snowflake warehouse to host the app", default="streamlit" + title="Snowflake warehouse to host the app", default=None ) main_file: Optional[Path] = Field( title="Entrypoint file of the Streamlit app", default="streamlit_app.py" diff --git a/tests/api/utils/test_definition_rendering.py b/tests/api/utils/test_definition_rendering.py index f25f47de7a..4cb3225b80 100644 --- a/tests/api/utils/test_definition_rendering.py +++ b/tests/api/utils/test_definition_rendering.py @@ -196,7 +196,6 @@ def test_resolve_variables_in_project_cross_project_dependencies(): "streamlit": { "name": "my_app", "main_file": "streamlit_app.py", - "query_warehouse": "streamlit", "stage": "streamlit", }, "env": ProjectEnvironment( diff --git a/tests/streamlit/test_streamlit_manager.py b/tests/streamlit/test_streamlit_manager.py index 4f04fe854c..0fcfad4ec0 100644 --- a/tests/streamlit/test_streamlit_manager.py +++ b/tests/streamlit/test_streamlit_manager.py @@ -134,6 +134,44 @@ def test_deploy_streamlit_with_comment( ) +@mock.patch("snowflake.cli._plugins.streamlit.manager.StageManager") +@mock.patch("snowflake.cli._plugins.streamlit.manager.StreamlitManager.get_url") +@mock.patch("snowflake.cli._plugins.streamlit.manager.StreamlitManager.execute_query") +@mock_streamlit_exists +def test_deploy_streamlit_with_default_warehouse( + mock_execute_query, _, mock_stage_manager, temp_dir +): + mock_stage_manager().get_standard_stage_prefix.return_value = "stage_root" + + main_file = Path(temp_dir) / "main.py" + main_file.touch() + + st = StreamlitEntityModel( + type="streamlit", + identifier="my_streamlit_app", + title="MyStreamlit", + main_file=str(main_file), + artifacts=[main_file], + comment="This is a test comment", + ) + + StreamlitManager(MagicMock(database="DB", schema="SH")).deploy( + streamlit=st, replace=False + ) + + mock_execute_query.assert_called_once_with( + dedent( + f"""\ + CREATE STREAMLIT IDENTIFIER('DB.SH.my_streamlit_app') + ROOT_LOCATION = 'stage_root' + MAIN_FILE = '{main_file}' + QUERY_WAREHOUSE = 'streamlit' + TITLE = 'MyStreamlit' + COMMENT = 'This is a test comment'""" + ) + ) + + @mock.patch("snowflake.cli._plugins.streamlit.manager.StreamlitManager.execute_query") @mock_streamlit_exists def test_execute_streamlit(mock_execute_query):