Skip to content

Commit

Permalink
replace app method of get existing info with facade one
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-mchok committed Dec 2, 2024
1 parent 0b4c0fd commit f2d4ff9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/snowflake/cli/_plugins/nativeapp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from snowflake.cli._plugins.nativeapp.entities.application_package import (
ApplicationPackageEntityModel,
)
from snowflake.cli._plugins.nativeapp.sf_facade import get_snowflake_facade
from snowflake.cli._plugins.nativeapp.v2_conversions.compat import (
find_entity,
force_project_definition_v2,
Expand Down Expand Up @@ -198,7 +199,7 @@ def app_open(
)
app_id = options["app_entity_id"]
app = ws.get_entity(app_id)
if app.get_existing_app_info():
if get_snowflake_facade().get_existing_app_info(app.name, app.role):
typer.launch(app.get_snowsight_url())
return MessageResult(f"Snowflake Native App opened in browser.")
else:
Expand Down
15 changes: 6 additions & 9 deletions src/snowflake/cli/_plugins/nativeapp/entities/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,9 @@ def action_drop(
needs_confirm = True

# 1. If existing application is not found, exit gracefully
show_obj_row = self.get_existing_app_info()
show_obj_row = get_snowflake_facade().get_existing_app_info(
self.name, self.role
)
if show_obj_row is None:
self.console.warning(
f"Role {self.role} does not own any application object with the name {self.name}, or the application object does not exist."
Expand Down Expand Up @@ -689,7 +691,9 @@ def create_or_upgrade_app(
)

# 1. Check for an existing application by the same name
show_app_row = self.get_existing_app_info()
show_app_row = get_snowflake_facade().get_existing_app_info(
self.name, self.role
)

stage_fqn = stage_fqn or package.stage_fqn

Expand Down Expand Up @@ -754,13 +758,6 @@ def use_application_warehouse(self):
)
)

def get_existing_app_info(self) -> Optional[dict]:
"""
Check for an existing application object by the same name as in project definition, in account.
It executes a 'show applications like' query and returns the result as single row, if one exists.
"""
return get_snowflake_facade().get_existing_app_info(self.name, self.role)

def drop_application_before_upgrade(
self,
policy: PolicyBase,
Expand Down
5 changes: 3 additions & 2 deletions tests/nativeapp/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
ObjectPropertyNotFoundError,
SetupScriptFailedValidation,
)
from snowflake.cli._plugins.nativeapp.sf_facade import get_snowflake_facade
from snowflake.cli._plugins.stage.diff import (
DiffResult,
StagePathType,
Expand Down Expand Up @@ -521,7 +522,7 @@ def test_get_existing_app_info_app_exists(
dm = _get_dm()
app_model: ApplicationEntityModel = dm.project_definition.entities["myapp"]
app = ApplicationEntity(app_model, workspace_context)
show_obj_row = app.get_existing_app_info()
show_obj_row = get_snowflake_facade().get_existing_app_info(app.name, app.role)
assert show_obj_row is not None
assert show_obj_row[NAME_COL] == "MYAPP"
assert mock_execute.mock_calls == expected
Expand Down Expand Up @@ -557,7 +558,7 @@ def test_get_existing_app_info_app_does_not_exist(
dm = _get_dm()
app_model: ApplicationEntityModel = dm.project_definition.entities["myapp"]
app = ApplicationEntity(app_model, workspace_context)
show_obj_row = app.get_existing_app_info()
show_obj_row = get_snowflake_facade().get_existing_app_info(app.name, app.role)
assert show_obj_row is None
assert mock_execute.mock_calls == expected

Expand Down

0 comments on commit f2d4ff9

Please sign in to comment.