From b54ffaf969980a5ffda62b565a1c1ba7bdab75b8 Mon Sep 17 00:00:00 2001 From: Jorge Vasquez Rojas Date: Mon, 26 Aug 2024 13:30:29 -0600 Subject: [PATCH] Fix snow git execute with directory un lower case --- RELEASE-NOTES.md | 3 +- src/snowflake/cli/_plugins/git/manager.py | 10 ++--- src/snowflake/cli/_plugins/stage/manager.py | 38 ++++++++++++------- tests_integration/__snapshots__/test_git.ambr | 9 ----- .../stage_execute/ScriptInCamelCase.sql | 1 - 5 files changed, 30 insertions(+), 31 deletions(-) delete mode 100644 tests_integration/test_data/projects/stage_execute/ScriptInCamelCase.sql diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 415758ae1c..2137c9c1d6 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -23,7 +23,7 @@ * Added templates expansion of arbitrary files for Native Apps through `templates` processor. ## Fixes and improvements - +* Fixed git execute not working with upper case in directory name. # v3.0.0 ## Backward incompatibility @@ -57,7 +57,6 @@ * Fix error handling and improve messaging when no artifacts provided. * Improved error message for incompatible parameters. * Fixed SQL error when running `snow app version create` and `snow app version drop` with a version name that isn't a valid Snowflake unquoted identifier -* Fixed git execute is not working with upper case in directory name. # v2.8.0 ## Backward incompatibility diff --git a/src/snowflake/cli/_plugins/git/manager.py b/src/snowflake/cli/_plugins/git/manager.py index a143191b9e..0edb6aecb6 100644 --- a/src/snowflake/cli/_plugins/git/manager.py +++ b/src/snowflake/cli/_plugins/git/manager.py @@ -41,11 +41,11 @@ def __init__(self, stage_path: str): @property def path(self) -> str: - return ( - f"{self.stage_name}{self.directory}" - if self.stage_name.endswith("/") - else f"{self.stage_name}/{self.directory}" - ) + return f"{self.stage_name.rstrip('/')}/{self.directory}" + + @property + def full_path(self) -> str: + return f"{self.stage.rstrip('/')}/{self.directory}" def add_stage_prefix(self, file_path: str) -> str: stage = Path(self.stage).parts[0] diff --git a/src/snowflake/cli/_plugins/stage/manager.py b/src/snowflake/cli/_plugins/stage/manager.py index 3d2ad371b0..f01612343d 100644 --- a/src/snowflake/cli/_plugins/stage/manager.py +++ b/src/snowflake/cli/_plugins/stage/manager.py @@ -73,6 +73,10 @@ def get_directory(stage_path: str) -> str: def path(self) -> str: raise NotImplementedError + @property + def full_path(self) -> str: + raise NotImplementedError + def add_stage_prefix(self, file_path: str) -> str: raise NotImplementedError @@ -112,18 +116,17 @@ def __init__(self, stage_path: str): self.directory = self.get_directory(stage_path) self.stage = StageManager.get_stage_from_path(stage_path) stage_name = self.stage.split(".")[-1] - if stage_name.startswith("@"): - stage_name = stage_name[1:] + stage_name = stage_name[1:] if stage_name.startswith("@") else stage_name self.stage_name = stage_name self.is_directory = True if stage_path.endswith("/") else False @property def path(self) -> str: - return ( - f"{self.stage_name}{self.directory}" - if self.stage_name.endswith("/") - else f"{self.stage_name}/{self.directory}" - ) + return f"{self.stage_name.rstrip('/')}/{self.directory}" + + @property + def full_path(self) -> str: + return f"{self.stage.rstrip('/')}/{self.directory}" def add_stage_prefix(self, file_path: str) -> str: stage = Path(self.stage).parts[0] @@ -154,6 +157,10 @@ def __init__(self, stage_path: str): def path(self) -> str: return f"{self.directory}" + @property + def full_path(self) -> str: + return f"{self.stage}/{self.directory}" + def add_stage_prefix(self, file_path: str) -> str: return f"{self.stage}/{file_path}" @@ -320,9 +327,14 @@ def execute( ): stage_path_parts = self._stage_path_part_factory(stage_path) all_files_list = self._get_files_list_from_stage(stage_path_parts) + all_files_with_stage_name_prefix = [ + stage_path_parts.add_stage_prefix(file) for file in all_files_list + ] # filter files from stage if match stage_path pattern - filtered_file_list = self._filter_files_list(stage_path_parts, all_files_list) + filtered_file_list = self._filter_files_list( + stage_path_parts, all_files_with_stage_name_prefix + ) if not filtered_file_list: raise ClickException(f"No files matched pattern '{stage_path}'") @@ -343,7 +355,7 @@ def execute( ) for file_path in sorted_file_path_list: - file_stage_path = stage_path_parts.add_stage_prefix(file_path) + file_stage_path = self.get_standard_stage_prefix(file_path) if file_path.endswith(".py"): result = self._execute_python( file_stage_path=file_stage_path, @@ -378,13 +390,11 @@ def _filter_files_list( if not stage_path_parts.directory: return self._filter_supported_files(files_on_stage) - stage_path = stage_path_parts.path.lower() + stage_path = stage_path_parts.full_path # Exact file path was provided if stage_path in file list - for file in files_on_stage: - if file.lower() != stage_path: - continue - filtered_files = self._filter_supported_files([file]) + if stage_path in files_on_stage: + filtered_files = self._filter_supported_files([stage_path]) if filtered_files: return filtered_files else: diff --git a/tests_integration/__snapshots__/test_git.ambr b/tests_integration/__snapshots__/test_git.ambr index d8ed7a7549..984e3e5a17 100644 --- a/tests_integration/__snapshots__/test_git.ambr +++ b/tests_integration/__snapshots__/test_git.ambr @@ -8,12 +8,3 @@ }), ]) # --- -# name: test_execute_with_name_in_camel_case - list([ - dict({ - 'Error': None, - 'File': '@SNOWCLI_TESTING_REPO/branches/main/tests_integration/test_data/projects/stage_execute/ScriptInCamelCase.sql', - 'Status': 'SUCCESS', - }), - ]) -# --- diff --git a/tests_integration/test_data/projects/stage_execute/ScriptInCamelCase.sql b/tests_integration/test_data/projects/stage_execute/ScriptInCamelCase.sql deleted file mode 100644 index 5617ac0270..0000000000 --- a/tests_integration/test_data/projects/stage_execute/ScriptInCamelCase.sql +++ /dev/null @@ -1 +0,0 @@ -select 'ScriptInCamelCase.sql';