Skip to content

Commit

Permalink
[SNOW1456079] Change patch to Optional[int] (#1169)
Browse files Browse the repository at this point in the history
Changes `snow app version create --patch` to require an integer for the patch number since that's what the backend expects (passing in a string results in a SQL compilation error).
  • Loading branch information
sfc-gh-fcampbell authored Jun 6, 2024
1 parent aef3e82 commit 8e53182
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 115 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

## New additions
* Added `snow app bundle` command that prepares a local folder in the project directory with artifacts to be uploaded to a stage as part of creating a Snowflake Native App.
* Changed `snow app version create --patch` to require an integer patch number, aligning with what Snowflake expects
* Added `snow notebook` commands:
* `snow notebook execute` enabling head-less execution of a notebook.
* `snow notebook create` proving an option to create a Snowflake Notebook from a file on stage.
Expand Down
2 changes: 1 addition & 1 deletion src/snowflake/cli/plugins/nativeapp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def app_run(
help=f"""The version defined in an existing application package from which you want to create an application object.
The application object and application package names are determined from the project definition file.""",
),
patch: Optional[str] = typer.Option(
patch: Optional[int] = typer.Option(
None,
"--patch",
help=f"""The patch number under the given `--version` defined in an existing application package that should be used to create an application object.
Expand Down
4 changes: 2 additions & 2 deletions src/snowflake/cli/plugins/nativeapp/run_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def upgrade_app(
policy: PolicyBase,
is_interactive: bool,
version: Optional[str] = None,
patch: Optional[str] = None,
patch: Optional[int] = None,
):

patch_clause = f"patch {patch}" if patch else ""
Expand Down Expand Up @@ -280,7 +280,7 @@ def process(
self,
policy: PolicyBase,
version: Optional[str] = None,
patch: Optional[str] = None,
patch: Optional[int] = None,
from_release_directive: bool = False,
is_interactive: bool = False,
*args,
Expand Down
2 changes: 1 addition & 1 deletion src/snowflake/cli/plugins/nativeapp/version/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def create(
None,
help=f"""Version to define in your application package. If the version already exists, an auto-incremented patch is added to the version instead. Defaults to the version specified in the `manifest.yml` file.""",
),
patch: Optional[str] = typer.Option(
patch: Optional[int] = typer.Option(
None,
"--patch",
help=f"""The patch number you want to create for an existing version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def add_new_version(self, version: str) -> None:
f"Version {version} created for application package {self.package_name}."
)

def add_new_patch_to_version(self, version: str, patch: Optional[str] = None):
def add_new_patch_to_version(self, version: str, patch: Optional[int] = None):
"""
Add a new patch, optionally a custom one, to an existing version in an application package.
"""
Expand Down Expand Up @@ -149,7 +149,7 @@ def add_new_patch_to_version(self, version: str, patch: Optional[str] = None):
def process(
self,
version: Optional[str],
patch: Optional[str],
patch: Optional[int],
policy: PolicyBase,
git_policy: PolicyBase,
is_interactive: bool,
Expand Down
225 changes: 116 additions & 109 deletions tests/__snapshots__/test_help_messages.ambr

Large diffs are not rendered by default.

91 changes: 91 additions & 0 deletions tests_integration/nativeapp/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,94 @@ def test_nativeapp_version_create_3_patches(
env=TEST_ENV,
)
assert result.exit_code == 0


@pytest.mark.integration
@pytest.mark.parametrize("project_definition_files", ["integration"], indirect=True)
def test_nativeapp_version_create_patch_is_integer(
runner,
snowflake_session,
project_definition_files: List[Path],
):
project_name = "integration"
project_dir = project_definition_files[0].parent
with pushd(project_dir):
try:
package_name = f"{project_name}_pkg_{USER_NAME}".upper()

# create initial version
result = runner.invoke_with_connection_json(
["app", "version", "create", "v1", "--force", "--skip-git-check"],
env=TEST_ENV,
)
assert result.exit_code == 0

# create non-integer patch
result = runner.invoke_with_connection_json(
[
"app",
"version",
"create",
"v1",
"--force",
"--skip-git-check",
"--patch",
"foo",
],
env=TEST_ENV,
)
assert result.exit_code == 2
assert (
"Invalid value for '--patch': 'foo' is not a valid integer."
in result.output
)

# create integer patch
result = runner.invoke_with_connection_json(
[
"app",
"version",
"create",
"v1",
"--force",
"--skip-git-check",
"--patch",
"1",
],
env=TEST_ENV,
)
assert result.exit_code == 0

# drop the version
result_drop = runner.invoke_with_connection_json(
["app", "version", "drop", "v1", "--force"],
env=TEST_ENV,
)
assert result_drop.exit_code == 0

# ensure there are no versions now
actual = runner.invoke_with_connection_json(
["app", "version", "list"], env=TEST_ENV
)
assert len(actual.json) == 0

# make sure we always delete the package
result = runner.invoke_with_connection_json(
["app", "teardown"],
env=TEST_ENV,
)
assert result.exit_code == 0

expect = snowflake_session.execute_string(
f"show application packages like '{package_name}'"
)
assert not_contains_row_with(
row_from_snowflake_session(expect), {"name": package_name}
)
finally:
# teardown is idempotent, so we can execute it again with no ill effects
result = runner.invoke_with_connection_json(
["app", "teardown", "--force"],
env=TEST_ENV,
)
assert result.exit_code == 0

0 comments on commit 8e53182

Please sign in to comment.