From a4698a8bc37660db8cc4f329947cf62b84694c94 Mon Sep 17 00:00:00 2001 From: Tomasz Urbaszek Date: Fri, 25 Oct 2024 10:59:01 +0200 Subject: [PATCH 1/2] Move usage telemetry to post_execute callback --- src/snowflake/cli/api/commands/snow_typer.py | 10 ++++++---- src/snowflake/cli/api/connections.py | 1 + tests/app/test_telemetry.py | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/snowflake/cli/api/commands/snow_typer.py b/src/snowflake/cli/api/commands/snow_typer.py index 61f0a49f64..74bbd092c8 100644 --- a/src/snowflake/cli/api/commands/snow_typer.py +++ b/src/snowflake/cli/api/commands/snow_typer.py @@ -125,10 +125,7 @@ def pre_execute(execution: ExecutionMetadata, require_warehouse: bool = False): Pay attention to make this method safe to use if performed operations are not necessary for executing the command in proper way. """ - from snowflake.cli._app.telemetry import log_command_usage - log.debug("Executing command pre execution callback") - log_command_usage(execution) if require_warehouse and not SqlExecutionMixin().session_has_warehouse(): raise ClickException( "The command requires warehouse. No warehouse found in current connection." @@ -166,9 +163,14 @@ def post_execute(execution: ExecutionMetadata): Callback executed after running any command callable. Pay attention to make this method safe to use if performed operations are not necessary for executing the command in proper way. """ - from snowflake.cli._app.telemetry import flush_telemetry, log_command_result + from snowflake.cli._app.telemetry import ( + flush_telemetry, + log_command_result, + log_command_usage, + ) log.debug("Executing command post execution callback") + log_command_usage(execution) log_command_result(execution) flush_telemetry() diff --git a/src/snowflake/cli/api/connections.py b/src/snowflake/cli/api/connections.py index 1239d0d7f6..15574e8bff 100644 --- a/src/snowflake/cli/api/connections.py +++ b/src/snowflake/cli/api/connections.py @@ -80,6 +80,7 @@ def update(self, **updates): setattr(self, key, value) def update_from_config(self) -> ConnectionContext: + self.validate_and_complete() connection_config = get_connection_dict(connection_name=self.connection_name) if "private_key_path" in connection_config: connection_config["private_key_file"] = connection_config[ diff --git a/tests/app/test_telemetry.py b/tests/app/test_telemetry.py index cc32380ee5..fe2e9cf620 100644 --- a/tests/app/test_telemetry.py +++ b/tests/app/test_telemetry.py @@ -174,7 +174,7 @@ def test_failing_executing_command_sends_telemetry_data( # The method is called with a TelemetryData type, so we cast it to dict for simpler comparison result_command_event = ( mock_conn.return_value._telemetry.try_add_log_to_batch.call_args_list[ # noqa: SLF001 - 1 + 0 ] .args[0] .to_dict() From bd5fb19232970a85795c0af6ea5389499b50ad5f Mon Sep 17 00:00:00 2001 From: Tomasz Urbaszek Date: Fri, 25 Oct 2024 14:21:59 +0200 Subject: [PATCH 2/2] fixup! Move usage telemetry to post_execute callback --- tests_e2e/__snapshots__/test_installation.ambr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests_e2e/__snapshots__/test_installation.ambr b/tests_e2e/__snapshots__/test_installation.ambr index 98a5128707..ead7bc7801 100644 --- a/tests_e2e/__snapshots__/test_installation.ambr +++ b/tests_e2e/__snapshots__/test_installation.ambr @@ -14,7 +14,7 @@ Usage: snow [OPTIONS] COMMAND [ARGS]... - Snowflake CLI tool for developers. + Snowflake CLI tool for developers [v3.1.0] +- Options --------------------------------------------------------------------+ | --version Shows version of the Snowflake CLI |