From 27b0a87f7fc169541be38825508cd5bb659b51e0 Mon Sep 17 00:00:00 2001 From: Francois Campbell Date: Wed, 18 Sep 2024 09:47:22 -0400 Subject: [PATCH] Remove use of DictCursor for use_role (#1584) Query Redaction (an enterprise feature) also redacts column names, which breaks `DictCursor`. Let's remove it from `use_role` and use a column index since the query has a well-defined column order in its output. --- src/snowflake/cli/api/sql_execution.py | 11 +- tests/nativeapp/test_manager.py | 48 +++---- tests/nativeapp/test_project_model.py | 4 +- tests/nativeapp/test_run_processor.py | 136 +++++++++--------- tests/nativeapp/test_teardown_processor.py | 66 ++++----- .../test_version_create_processor.py | 36 ++--- .../nativeapp/test_version_drop_processor.py | 9 +- tests/stage/test_stage.py | 24 ++-- .../test_application_package_entity.py | 16 +-- 9 files changed, 170 insertions(+), 180 deletions(-) diff --git a/src/snowflake/cli/api/sql_execution.py b/src/snowflake/cli/api/sql_execution.py index 29eeda9263..c06834ce54 100644 --- a/src/snowflake/cli/api/sql_execution.py +++ b/src/snowflake/cli/api/sql_execution.py @@ -98,11 +98,7 @@ def use(self, object_type: ObjectType, name: str): ) def current_role(self) -> str: - *_, cursor = self._execute_string( - "select current_role()", cursor_class=DictCursor - ) - role_result = cursor.fetchone() - return role_result["CURRENT_ROLE()"] + return self._execute_query(f"select current_role()").fetchone()[0] @contextmanager def use_role(self, new_role: str): @@ -110,10 +106,7 @@ def use_role(self, new_role: str): Switches to a different role for a while, then switches back. This is a no-op if the requested role is already active. """ - role_result = self._execute_query( - f"select current_role()", cursor_class=DictCursor - ).fetchone() - prev_role = role_result["CURRENT_ROLE()"] + prev_role = self.current_role() is_different_role = new_role.lower() != prev_role.lower() if is_different_role: self._log.debug("Assuming different role: %s", new_role) diff --git a/tests/nativeapp/test_manager.py b/tests/nativeapp/test_manager.py index ddd49d03be..79c9033187 100644 --- a/tests/nativeapp/test_manager.py +++ b/tests/nativeapp/test_manager.py @@ -109,7 +109,7 @@ def test_sync_deploy_root_with_stage( temp_dir, mock_cursor, ): - mock_execute.return_value = mock_cursor([{"CURRENT_ROLE()": "old_role"}], []) + mock_execute.return_value = mock_cursor([("old_role",)], []) mock_diff_result = DiffResult(different=[StagePath("setup.sql")]) mock_compute_stage_diff.return_value = mock_diff_result mock_local_diff_with_stage.return_value = None @@ -132,7 +132,7 @@ def test_sync_deploy_root_with_stage( ) expected = [ - mock.call("select current_role()", cursor_class=DictCursor), + mock.call("select current_role()"), mock.call("use role new_role"), mock.call(f"create schema if not exists app_pkg.app_src"), mock.call( @@ -218,8 +218,8 @@ def test_get_app_pkg_distribution_in_snowflake(mock_execute, temp_dir, mock_curs side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( @@ -259,8 +259,8 @@ def test_get_app_pkg_distribution_in_snowflake_throws_programming_error( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( @@ -297,8 +297,8 @@ def test_get_app_pkg_distribution_in_snowflake_throws_execution_error( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), (mock_cursor([], []), mock.call("describe application package app_pkg")), @@ -329,8 +329,8 @@ def test_get_app_pkg_distribution_in_snowflake_throws_distribution_error( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( @@ -442,8 +442,8 @@ def test_get_existing_app_info_app_exists(mock_execute, temp_dir, mock_cursor): side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -484,8 +484,8 @@ def test_get_existing_app_info_app_does_not_exist(mock_execute, temp_dir, mock_c side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -515,8 +515,8 @@ def test_get_existing_app_pkg_info_app_pkg_exists(mock_execute, temp_dir, mock_c side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( @@ -562,8 +562,8 @@ def test_get_existing_app_pkg_info_app_pkg_does_not_exist( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( @@ -741,8 +741,8 @@ def test_create_app_pkg_no_existing_package( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( @@ -1162,8 +1162,8 @@ def test_validate_use_scratch_stage( ), ), ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( @@ -1224,8 +1224,8 @@ def test_validate_failing_drops_scratch_stage( ), ), ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( diff --git a/tests/nativeapp/test_project_model.py b/tests/nativeapp/test_project_model.py index 67c921fe94..4d8cb9bfef 100644 --- a/tests/nativeapp/test_project_model.py +++ b/tests/nativeapp/test_project_model.py @@ -242,9 +242,7 @@ def test_project_model_explicit_package_app_name_with_suffix( def test_project_model_falls_back_to_current_role( mock_connect, project_definition_files: List[Path], mock_ctx, mock_cursor ): - ctx = mock_ctx( - cursor=mock_cursor([{"CURRENT_ROLE()": CURRENT_ROLE}], []), role=None - ) + ctx = mock_ctx(cursor=mock_cursor([(CURRENT_ROLE,)], []), role=None) mock_connect.return_value = ctx project_defn = load_project(project_definition_files).project_definition diff --git a/tests/nativeapp/test_run_processor.py b/tests/nativeapp/test_run_processor.py index 91e49dc8b2..ffddca375d 100644 --- a/tests/nativeapp/test_run_processor.py +++ b/tests/nativeapp/test_run_processor.py @@ -103,8 +103,8 @@ def test_create_dev_app_w_warehouse_access_exception( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -162,8 +162,8 @@ def test_create_dev_app_create_new_w_no_additional_privileges( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -268,8 +268,8 @@ def test_create_or_upgrade_dev_app_with_warning( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -317,8 +317,8 @@ def test_create_dev_app_create_new_with_additional_privileges( side_effects, mock_execute_query_expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -327,8 +327,8 @@ def test_create_dev_app_create_new_with_additional_privileges( ), (None, mock.call("use warehouse app_warehouse")), ( - mock_cursor([{"CURRENT_ROLE()": "app_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("app_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( @@ -391,8 +391,8 @@ def test_create_dev_app_create_new_w_missing_warehouse_exception( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -474,8 +474,8 @@ def test_create_dev_app_incorrect_properties( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -525,8 +525,8 @@ def test_create_dev_app_incorrect_owner( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -576,8 +576,8 @@ def test_create_dev_app_no_diff_changes( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -631,8 +631,8 @@ def test_create_dev_app_w_diff_changes( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -686,8 +686,8 @@ def test_create_dev_app_recreate_w_missing_warehouse_exception( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -742,8 +742,8 @@ def test_create_dev_app_create_new_quoted( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -828,8 +828,8 @@ def test_create_dev_app_create_new_quoted_override( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -901,8 +901,8 @@ def test_create_dev_app_recreate_app_when_orphaned( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -918,8 +918,8 @@ def test_create_dev_app_recreate_app_when_orphaned( ), (None, mock.call("drop application myapp")), ( - mock_cursor([{"CURRENT_ROLE()": "app_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("app_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( @@ -995,8 +995,8 @@ def test_create_dev_app_recreate_app_when_orphaned_requires_cascade( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -1015,8 +1015,8 @@ def test_create_dev_app_recreate_app_when_orphaned_requires_cascade( mock.call("drop application myapp"), ), ( - mock_cursor([{"CURRENT_ROLE()": "app_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("app_role",)], []), + mock.call("select current_role()"), ), ( mock_cursor( @@ -1029,8 +1029,8 @@ def test_create_dev_app_recreate_app_when_orphaned_requires_cascade( ), (None, mock.call("drop application myapp cascade")), ( - mock_cursor([{"CURRENT_ROLE()": "app_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("app_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( @@ -1107,8 +1107,8 @@ def test_create_dev_app_recreate_app_when_orphaned_requires_cascade_unknown_obje side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -1127,8 +1127,8 @@ def test_create_dev_app_recreate_app_when_orphaned_requires_cascade_unknown_obje mock.call("drop application myapp"), ), ( - mock_cursor([{"CURRENT_ROLE()": "app_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("app_role",)], []), + mock.call("select current_role()"), ), ( ProgrammingError(errno=APPLICATION_NO_LONGER_AVAILABLE), @@ -1136,8 +1136,8 @@ def test_create_dev_app_recreate_app_when_orphaned_requires_cascade_unknown_obje ), (None, mock.call("drop application myapp cascade")), ( - mock_cursor([{"CURRENT_ROLE()": "app_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("app_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( @@ -1200,8 +1200,8 @@ def test_upgrade_app_warehouse_error( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -1265,8 +1265,8 @@ def test_upgrade_app_incorrect_owner( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -1321,8 +1321,8 @@ def test_upgrade_app_succeeds( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -1377,8 +1377,8 @@ def test_upgrade_app_fails_generic_error( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -1448,8 +1448,8 @@ def test_upgrade_app_fails_upgrade_restriction_error( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -1511,8 +1511,8 @@ def test_versioned_app_upgrade_to_unversioned( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -1531,8 +1531,8 @@ def test_versioned_app_upgrade_to_unversioned( ), (None, mock.call("drop application myapp")), ( - mock_cursor([{"CURRENT_ROLE()": "app_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("app_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( @@ -1616,8 +1616,8 @@ def test_upgrade_app_fails_drop_fails( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -1686,8 +1686,8 @@ def test_upgrade_app_recreate_app( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -1703,8 +1703,8 @@ def test_upgrade_app_recreate_app( ), (None, mock.call("drop application myapp")), ( - mock_cursor([{"CURRENT_ROLE()": "app_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("app_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( @@ -1846,8 +1846,8 @@ def test_upgrade_app_recreate_app_from_version( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -1863,8 +1863,8 @@ def test_upgrade_app_recreate_app_from_version( ), (None, mock.call("drop application myapp")), ( - mock_cursor([{"CURRENT_ROLE()": "app_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("app_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( @@ -1925,8 +1925,8 @@ def test_get_existing_version_info(mock_execute, temp_dir, mock_cursor): side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( diff --git a/tests/nativeapp/test_teardown_processor.py b/tests/nativeapp/test_teardown_processor.py index ee1aeb8a22..b67e103b95 100644 --- a/tests/nativeapp/test_teardown_processor.py +++ b/tests/nativeapp/test_teardown_processor.py @@ -75,8 +75,8 @@ def test_drop_generic_object_success(mock_execute, temp_dir, mock_cursor): side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), (None, mock.call("drop application myapp")), @@ -111,18 +111,18 @@ def test_drop_generic_object_failure_w_exception( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call.execute_sql("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), - (None, mock.call.execute_sql("use role package_role")), + (None, mock.call("use role package_role")), ( ProgrammingError( msg="Object does not exist, or operation cannot be performed.", errno=DOES_NOT_EXIST_OR_CANNOT_BE_PERFORMED, ), - mock.call.execute_sql("drop application package app_pkg"), + mock.call("drop application package app_pkg"), ), - (None, mock.call.execute_sql("use role old_role")), + (None, mock.call("use role old_role")), ] ) mock_execute.side_effect = side_effects @@ -264,8 +264,8 @@ def test_drop_application_has_special_comment_and_quoted_name( [ # Show apps ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -287,8 +287,8 @@ def test_drop_application_has_special_comment_and_quoted_name( (None, mock.call("use role old_role")), # Drop app ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), (None, mock.call('drop application "My Application"')), @@ -389,8 +389,8 @@ def test_drop_application_user_allows_drop( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), (None, mock.call("use role old_role")), @@ -530,8 +530,8 @@ def test_show_versions_failure_w_exception( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -585,8 +585,8 @@ def test_drop_package_no_mismatch_no_drop( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( @@ -652,8 +652,8 @@ def test_drop_package_variable_mismatch_allowed_user_allows_drop( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( @@ -725,8 +725,8 @@ def test_drop_package_variable_mistmatch_w_special_comment_auto_drop( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( @@ -780,8 +780,8 @@ def test_drop_package_variable_mistmatch_w_special_comment_quoted_name_auto_drop [ # Show app pkg ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( @@ -803,8 +803,8 @@ def test_drop_package_variable_mistmatch_w_special_comment_quoted_name_auto_drop (None, mock.call("use role old_role")), # Show versions ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( @@ -817,8 +817,8 @@ def test_drop_package_variable_mistmatch_w_special_comment_quoted_name_auto_drop (None, mock.call("use role old_role")), # Drop app pkg ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), (None, mock.call('drop application package "My Package"')), @@ -880,8 +880,8 @@ def test_drop_package_variable_mistmatch_no_special_comment_user_prohibits_drop( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( @@ -950,8 +950,8 @@ def test_drop_package_variable_mistmatch_no_special_comment_user_allows_drop( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( @@ -1002,8 +1002,8 @@ def test_drop_package_idempotent( side_effects_for_execute, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( diff --git a/tests/nativeapp/test_version_create_processor.py b/tests/nativeapp/test_version_create_processor.py index b418addc5d..4d542956af 100644 --- a/tests/nativeapp/test_version_create_processor.py +++ b/tests/nativeapp/test_version_create_processor.py @@ -67,8 +67,8 @@ def test_get_existing_release_direction_info(mock_execute, temp_dir, mock_cursor side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( @@ -113,8 +113,8 @@ def test_add_version(mock_execute, temp_dir, mock_cursor, version, version_ident side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( @@ -159,8 +159,8 @@ def test_add_new_patch_auto( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( @@ -205,8 +205,8 @@ def test_add_new_patch_custom( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( @@ -389,8 +389,8 @@ def test_process_no_existing_release_directives_or_versions( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), (None, mock.call("use role old_role")), @@ -489,8 +489,8 @@ def test_process_no_existing_release_directives_w_existing_version( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), (None, mock.call("use role old_role")), @@ -590,8 +590,8 @@ def test_process_existing_release_directives_user_does_not_proceed( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), (None, mock.call("use role old_role")), @@ -698,8 +698,8 @@ def test_process_existing_release_directives_w_existing_version_two( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), (None, mock.call("use role old_role")), @@ -795,8 +795,8 @@ def test_process_package_no_magic_comment( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), (None, mock.call("use role old_role")), diff --git a/tests/nativeapp/test_version_drop_processor.py b/tests/nativeapp/test_version_drop_processor.py index 9136f25d21..9e9818b66e 100644 --- a/tests/nativeapp/test_version_drop_processor.py +++ b/tests/nativeapp/test_version_drop_processor.py @@ -30,7 +30,6 @@ NativeAppVersionDropProcessor, ) from snowflake.cli.api.project.definition_manager import DefinitionManager -from snowflake.connector.cursor import DictCursor from tests.nativeapp.patch_utils import mock_get_app_pkg_distribution_in_sf from tests.nativeapp.utils import ( @@ -207,8 +206,8 @@ def test_process_drop_from_manifest( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( @@ -276,8 +275,8 @@ def test_process_drop_specific_version( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role package_role")), ( diff --git a/tests/stage/test_stage.py b/tests/stage/test_stage.py index 2cb452a7c7..d25818c1f1 100644 --- a/tests/stage/test_stage.py +++ b/tests/stage/test_stage.py @@ -642,11 +642,11 @@ def test_stage_print_result_for_get_all_files_from_stage_recursive( @mock.patch(f"{STAGE_MANAGER}._execute_query") def test_stage_internal_remove(mock_execute, mock_cursor): - mock_execute.return_value = mock_cursor([{"CURRENT_ROLE()": "old_role"}], []) + mock_execute.return_value = mock_cursor([("old_role",)], []) sm = StageManager() sm.remove("stageName", "my/file/foo.csv", "new_role") expected = [ - mock.call("select current_role()", cursor_class=DictCursor), + mock.call("select current_role()"), mock.call("use role new_role"), mock.call("remove @stageName/my/file/foo.csv"), mock.call("use role old_role"), @@ -656,11 +656,11 @@ def test_stage_internal_remove(mock_execute, mock_cursor): @mock.patch(f"{STAGE_MANAGER}._execute_query") def test_stage_internal_remove_quoted(mock_execute, mock_cursor): - mock_execute.return_value = mock_cursor([{"CURRENT_ROLE()": "old_role"}], []) + mock_execute.return_value = mock_cursor([("old_role",)], []) sm = StageManager() sm.remove('"stage name"', "my/file/foo.csv", "new_role") expected = [ - mock.call("select current_role()", cursor_class=DictCursor), + mock.call("select current_role()"), mock.call("use role new_role"), mock.call("remove '@\"stage name\"/my/file/foo.csv'"), mock.call("use role old_role"), @@ -670,11 +670,11 @@ def test_stage_internal_remove_quoted(mock_execute, mock_cursor): @mock.patch(f"{STAGE_MANAGER}._execute_query") def test_stage_internal_remove_no_role_change(mock_execute, mock_cursor): - mock_execute.return_value = mock_cursor([{"CURRENT_ROLE()": "old_role"}], []) + mock_execute.return_value = mock_cursor([("old_role",)], []) sm = StageManager() sm.remove("stageName", "my/file/foo.csv", "old_role") expected = [ - mock.call("select current_role()", cursor_class=DictCursor), + mock.call("select current_role()"), mock.call("remove @stageName/my/file/foo.csv"), ] assert mock_execute.mock_calls == expected @@ -682,12 +682,12 @@ def test_stage_internal_remove_no_role_change(mock_execute, mock_cursor): @mock.patch(f"{STAGE_MANAGER}._execute_query") def test_stage_internal_put(mock_execute, mock_cursor): - mock_execute.return_value = mock_cursor([{"CURRENT_ROLE()": "old_role"}], []) + mock_execute.return_value = mock_cursor([("old_role",)], []) with TemporaryDirectory() as tmp_dir: sm = StageManager() sm.put(Path(tmp_dir).resolve(), "stageName", role="new_role") expected = [ - mock.call("select current_role()", cursor_class=DictCursor), + mock.call("select current_role()"), mock.call("use role new_role"), mock.call( f"put file://{Path(tmp_dir).resolve()} @stageName auto_compress=false parallel=4 overwrite=False" @@ -699,12 +699,12 @@ def test_stage_internal_put(mock_execute, mock_cursor): @mock.patch(f"{STAGE_MANAGER}._execute_query") def test_stage_internal_put_quoted_stage(mock_execute, mock_cursor): - mock_execute.return_value = mock_cursor([{"CURRENT_ROLE()": "old_role"}], []) + mock_execute.return_value = mock_cursor([("old_role",)], []) with TemporaryDirectory() as tmp_dir: sm = StageManager() sm.put(Path(tmp_dir).resolve(), '"stage name"', role="new_role") expected = [ - mock.call("select current_role()", cursor_class=DictCursor), + mock.call("select current_role()"), mock.call("use role new_role"), mock.call( f"put file://{Path(tmp_dir).resolve()} '@\"stage name\"' auto_compress=false parallel=4 overwrite=False" @@ -733,7 +733,7 @@ def test_stage_internal_put_quoted_stage(mock_execute, mock_cursor): def test_stage_internal_put_quoted_path( mock_execute, mock_cursor, raw_path, expected_uri ): - mock_execute.return_value = mock_cursor([{"CURRENT_ROLE()": "old_role"}], []) + mock_execute.return_value = mock_cursor([("old_role",)], []) with TemporaryDirectory() as tmp_dir: sm = StageManager() tmp_dir = Path(tmp_dir).resolve() @@ -741,7 +741,7 @@ def test_stage_internal_put_quoted_path( src_uri = expected_uri.replace("{}", str(tmp_dir)) sm.put(src_path, "stageName", role="new_role") expected = [ - mock.call("select current_role()", cursor_class=DictCursor), + mock.call("select current_role()"), mock.call("use role new_role"), mock.call( f"put {src_uri} @stageName auto_compress=false parallel=4 overwrite=False" diff --git a/tests/workspace/test_application_package_entity.py b/tests/workspace/test_application_package_entity.py index da86b24bad..be2498affe 100644 --- a/tests/workspace/test_application_package_entity.py +++ b/tests/workspace/test_application_package_entity.py @@ -83,8 +83,8 @@ def test_deploy( side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -106,8 +106,8 @@ def test_deploy( ), (None, mock.call("use role old_role")), ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), ( @@ -123,8 +123,8 @@ def test_deploy( ), (None, mock.call("use role old_role")), ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call("use role app_role")), (None, mock.call("use role old_role")), @@ -172,8 +172,8 @@ def test_version_list(mock_execute, mock_cursor): side_effects, expected = mock_execute_helper( [ ( - mock_cursor([{"CURRENT_ROLE()": "old_role"}], []), - mock.call("select current_role()", cursor_class=DictCursor), + mock_cursor([("old_role",)], []), + mock.call("select current_role()"), ), (None, mock.call(f"use role {package_role}")), (