Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move create/alter app upgrade calls to sql facade to reclassify errors cause by setup script execution #1870

Merged
merged 29 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b5db358
convert create/upgrade app calls to sqlfacade; TODO: refactor test_ru…
sfc-gh-mchok Nov 15, 2024
4f48b11
migrate all tests to sql facade for create/upgrade
sfc-gh-mchok Nov 19, 2024
5c0d52d
update event sharing tests for refactor
sfc-gh-mchok Nov 20, 2024
6595561
merge success messages for tests
sfc-gh-mchok Nov 21, 2024
a71f4a9
move error handling to facade
sfc-gh-mchok Nov 21, 2024
f1f00f0
further overhauls to create/upgrade to make uniform, fix version not …
sfc-gh-mchok Nov 22, 2024
cab6e8b
update event sharing tests
sfc-gh-mchok Nov 25, 2024
945544f
remove unused mock arg
sfc-gh-mchok Nov 25, 2024
f345027
Merge branch 'main' into mchok-create-or-alter-app-to-sqlfacade
sfc-gh-mchok Nov 26, 2024
ef653ab
extract app entity properties, move upgrade restriction codes to sql …
sfc-gh-mchok Nov 26, 2024
da876f0
move grants for application to sf facade
sfc-gh-mchok Nov 26, 2024
34bf540
move grant privileges call to app entity
sfc-gh-mchok Nov 26, 2024
cc7aeee
separate telemetry error check from rest of upgrade logic and rewrite…
sfc-gh-mchok Nov 26, 2024
8d4e35b
move get_existing_app_info to sql facade
sfc-gh-mchok Nov 26, 2024
52af246
change error handling to be default our fault, add list of error code…
sfc-gh-mchok Nov 27, 2024
57b7f3d
Merge branch 'main' into mchok-create-or-alter-app-to-sqlfacade
sfc-gh-mchok Nov 28, 2024
6205d72
unclassify user errors for get existing app info
sfc-gh-mchok Nov 28, 2024
cef4337
remove error codes to err on the side of caution
sfc-gh-mchok Nov 28, 2024
8c2a475
Merge branch 'main' into mchok-create-or-alter-app-to-sqlfacade
sfc-gh-mchok Nov 28, 2024
7639f2e
tests for sql facade (1/3)
sfc-gh-mchok Nov 28, 2024
94e797f
refactor test_run_processor tests (2/3)
sfc-gh-mchok Nov 29, 2024
1248c2b
refactor event sharing tests
sfc-gh-mchok Nov 30, 2024
d5159d7
add grant privileges to expected calls
sfc-gh-mchok Nov 30, 2024
92c20e0
Merge branch 'main' into mchok-create-or-alter-app-to-sqlfacade
sfc-gh-mchok Dec 2, 2024
0b4c0fd
add support exclusion for application( package) object types
sfc-gh-mchok Dec 2, 2024
f2d4ff9
replace app method of get existing info with facade one
sfc-gh-mchok Dec 2, 2024
c9f090e
fix tests after replacing get existing app info with facade version
sfc-gh-mchok Dec 2, 2024
0af4869
use _same_identifier for comparison
sfc-gh-mchok Dec 2, 2024
c051f5a
Merge branch 'main' into mchok-create-or-alter-app-to-sqlfacade
sfc-gh-melnacouzi Dec 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
452 changes: 184 additions & 268 deletions src/snowflake/cli/_plugins/nativeapp/entities/application.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from dataclasses import dataclass
from typing import Optional

from snowflake.cli._plugins.nativeapp.constants import (
Expand All @@ -8,25 +9,15 @@
ApplicationCreatedExternallyError,
)
from snowflake.cli._plugins.stage.manager import StageManager
from snowflake.cli.api.project.util import to_identifier


@dataclass
sfc-gh-mchok marked this conversation as resolved.
Show resolved Hide resolved
class SameAccountInstallMethod:
_requires_created_by_cli: bool
_from_release_directive: bool
version: Optional[str]
patch: Optional[int]

def __init__(
self,
requires_created_by_cli: bool,
version: Optional[str] = None,
patch: Optional[int] = None,
from_release_directive: bool = False,
):
self._requires_created_by_cli = requires_created_by_cli
self.version = version
self.patch = patch
self._from_release_directive = from_release_directive
version: Optional[str] = None
patch: Optional[int] = None
_from_release_directive: bool = False

sfc-gh-pjafari marked this conversation as resolved.
Show resolved Hide resolved
@classmethod
def unversioned_dev(cls):
Expand All @@ -39,7 +30,7 @@ def versioned_dev(cls, version: str, patch: Optional[int] = None):

@classmethod
def release_directive(cls):
return cls(False, from_release_directive=True)
return cls(False, _from_release_directive=True)

@property
def is_dev_mode(self) -> bool:
Expand All @@ -53,8 +44,9 @@ def using_clause(
return ""

if self.version:
version_clause = f"version {to_identifier(self.version)}"
sfc-gh-mchok marked this conversation as resolved.
Show resolved Hide resolved
patch_clause = f"patch {self.patch}" if self.patch else ""
return f"using version {self.version} {patch_clause}"
return f"using {version_clause} {patch_clause}"

stage_name = StageManager.quote_stage_name(stage_fqn)
return f"using {stage_name}"
Expand Down
80 changes: 80 additions & 0 deletions src/snowflake/cli/_plugins/nativeapp/sf_facade_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,83 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations

from typing import NoReturn

from click import ClickException
from snowflake.cli._plugins.nativeapp.sf_facade_constants import UseObjectType
from snowflake.cli.api.errno import (
APPLICATION_FILE_NOT_FOUND_ON_STAGE,
APPLICATION_INSTANCE_EMPTY_SETUP_SCRIPT,
APPLICATION_INSTANCE_FAILED_TO_RUN_SETUP_SCRIPT,
APPLICATION_INSTANCE_NO_ACTIVE_WAREHOUSE_FOR_CREATE_OR_UPGRADE,
APPLICATION_NO_LONGER_AVAILABLE,
APPLICATION_PACKAGE_CANNOT_SET_EXTERNAL_DISTRIBUTION_WITH_SPCS,
APPLICATION_PACKAGE_MANIFEST_CONTAINER_IMAGE_URL_BAD_VALUE,
APPLICATION_PACKAGE_MANIFEST_SPECIFIED_FILE_NOT_FOUND,
APPLICATION_PACKAGE_PATCH_DOES_NOT_EXIST,
CANNOT_GRANT_NON_MANIFEST_PRIVILEGE,
CANNOT_GRANT_OBJECT_NOT_IN_APP_PACKAGE,
CANNOT_GRANT_RESTRICTED_PRIVILEGE_TO_APP_PACKAGE_SHARE,
CANNOT_UPGRADE_FROM_LOOSE_FILES_TO_VERSION,
CANNOT_UPGRADE_FROM_VERSION_TO_LOOSE_FILES,
NATIVE_APPLICATION_MANIFEST_GENERIC_JSON_ERROR,
NATIVE_APPLICATION_MANIFEST_INVALID_SYNTAX,
NATIVE_APPLICATION_MANIFEST_UNEXPECTED_VALUE_FOR_PROPERTY,
NATIVE_APPLICATION_MANIFEST_UNRECOGNIZED_FIELD,
NO_REFERENCE_SET_FOR_DEFINITION,
NO_VERSIONS_AVAILABLE_FOR_ACCOUNT,
NOT_SUPPORTED_ON_DEV_MODE_APPLICATIONS,
ONLY_SUPPORTED_ON_DEV_MODE_APPLICATIONS,
ROLE_NOT_ASSIGNED,
SNOWSERVICES_IMAGE_MANIFEST_NOT_FOUND,
SNOWSERVICES_IMAGE_REPOSITORY_FAILS_TO_RETRIEVE_IMAGE_HASH_NEW,
SNOWSERVICES_IMAGE_REPOSITORY_IMAGE_IMPORT_TO_NATIVE_APP_FAIL,
VIEW_EXPANSION_FAILED,
)
from snowflake.connector import DatabaseError, Error, ProgrammingError

# Reasons why an `alter application ... upgrade` might fail
UPGRADE_RESTRICTION_CODES = {
CANNOT_UPGRADE_FROM_LOOSE_FILES_TO_VERSION,
CANNOT_UPGRADE_FROM_VERSION_TO_LOOSE_FILES,
ONLY_SUPPORTED_ON_DEV_MODE_APPLICATIONS,
NOT_SUPPORTED_ON_DEV_MODE_APPLICATIONS,
APPLICATION_NO_LONGER_AVAILABLE,
}

CREATE_OR_UPGRADE_APPLICATION_EXPECTED_USER_ERROR_CODES = {
APPLICATION_INSTANCE_FAILED_TO_RUN_SETUP_SCRIPT,
NATIVE_APPLICATION_MANIFEST_GENERIC_JSON_ERROR,
APPLICATION_INSTANCE_NO_ACTIVE_WAREHOUSE_FOR_CREATE_OR_UPGRADE,
# when setup script/manifest/readme isn't on the stage
APPLICATION_FILE_NOT_FOUND_ON_STAGE,
NATIVE_APPLICATION_MANIFEST_UNRECOGNIZED_FIELD,
SNOWSERVICES_IMAGE_MANIFEST_NOT_FOUND,
# user tried to clone tables and it failed
VIEW_EXPANSION_FAILED,
# user tried to do something with a role that wasn't assigned to them
ROLE_NOT_ASSIGNED,
APPLICATION_PACKAGE_MANIFEST_SPECIFIED_FILE_NOT_FOUND,
SNOWSERVICES_IMAGE_REPOSITORY_IMAGE_IMPORT_TO_NATIVE_APP_FAIL,
APPLICATION_PACKAGE_PATCH_DOES_NOT_EXIST,
APPLICATION_PACKAGE_MANIFEST_CONTAINER_IMAGE_URL_BAD_VALUE,
SNOWSERVICES_IMAGE_REPOSITORY_FAILS_TO_RETRIEVE_IMAGE_HASH_NEW,
NATIVE_APPLICATION_MANIFEST_UNEXPECTED_VALUE_FOR_PROPERTY,
CANNOT_GRANT_NON_MANIFEST_PRIVILEGE,
NO_REFERENCE_SET_FOR_DEFINITION,
NATIVE_APPLICATION_MANIFEST_INVALID_SYNTAX,
CANNOT_GRANT_OBJECT_NOT_IN_APP_PACKAGE,
APPLICATION_PACKAGE_MANIFEST_SPECIFIED_FILE_NOT_FOUND,
# user tried installing from release directive and there are none available
NO_VERSIONS_AVAILABLE_FOR_ACCOUNT,
APPLICATION_PACKAGE_MANIFEST_CONTAINER_IMAGE_URL_BAD_VALUE,
APPLICATION_INSTANCE_EMPTY_SETUP_SCRIPT,
APPLICATION_PACKAGE_CANNOT_SET_EXTERNAL_DISTRIBUTION_WITH_SPCS,
CANNOT_GRANT_RESTRICTED_PRIVILEGE_TO_APP_PACKAGE_SHARE,
}


def handle_unclassified_error(err: Error | Exception, context: str) -> NoReturn:
"""
Expand Down Expand Up @@ -115,3 +186,12 @@ def __init__(
if role:
message += f" using role: {role}"
super().__init__(message)


class UpgradeApplicationRestrictionError(UserInputError):
"""
Raised when an alter application ... upgrade fails due to user error.
Must be caught and handled by the caller of an upgrade_application
"""

pass
Loading
Loading