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

[NADE][Bugfix] Use resolved app warehouse for regionless query #1292

Merged
merged 8 commits into from
Jul 15, 2024

Conversation

sfc-gh-bgoel
Copy link
Contributor

Pre-review checklist

  • I've confirmed that instructions included in README.md are still correct after my changes in the codebase.
  • I've added or updated automated unit tests to verify correctness of my new code.
  • I've added or updated integration tests to verify correctness of my new code.
  • I've confirmed that my changes are working by executing CLI's commands manually on MacOS.
  • I've confirmed that my changes are working by executing CLI's commands manually on Windows.
  • I've confirmed that my changes are up-to-date with the target branch.
  • I've described my changes in the release notes.
  • I've described my changes in the section below.

Changes description

As part of fetching the URL where the Native App is live, the CLI needs to execute a SQL query which requires the use of a warehouse. The application.warehouse property in the manager class resolves this to either be the app warehouse if found, or the one derived from the connection. Since this URL is pertaining to the app instance, we have decided to execute this query by only activating app warehouse.

@sfc-gh-bgoel sfc-gh-bgoel force-pushed the bgoel-regionless-redirect-bugfix branch from 5fc8649 to 58fb01d Compare July 8, 2024 13:16
@sfc-gh-bgoel sfc-gh-bgoel marked this pull request as ready for review July 8, 2024 17:20
@sfc-gh-bgoel sfc-gh-bgoel requested review from a team as code owners July 8, 2024 17:20
Copy link
Contributor

@sfc-gh-cgorrie sfc-gh-cgorrie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also audit other potential gaps we might have missed -- like post-deploy scripts or package scripts? We should use this new use_warehouse primitive everywhere it makes sense.

assert (
"Could not use warehouse MockWarehouse. Object does not exist, or operation cannot be performed."
in err.value.msg
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error message is now different because instead of calling use warehouse directly which uses our generic_error_handler, it calls the method self.use provided by the CLI which has its own error handling.

@sfc-gh-bgoel sfc-gh-bgoel force-pushed the bgoel-regionless-redirect-bugfix branch from d8a4638 to 0664030 Compare July 10, 2024 13:51
if new_wh is not None:
new_wh_id = to_identifier(new_wh)

if prev_wh is None and new_wh is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this logic is a bit too complicated.

  1. Why do we need to stay with prev_wh if new_wh is not defined? is it a valid use case that new_wh is None (especially when dealing with snow app run)? Shouldn't we just error?

  2. too many combinations. I suggest to simplify as follows if possible:

a) if new_wh is None, error out.
b) proceed to switch to new_wh if different from prev_wh.
c) yield
d) if prev_wh was None, do nothing, otherwise, switch back to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some concerns raised in the previous comments:

  1. It is possible that prev_wh is None, especially in the case when no default warehouse is assigned to a user, and hence current_warehouse() may return None. I do not have a way of verifying this as I do not have permissions to set up a new user in an account, but I do believe this is a case we need to account for since the bug ticket was created for a scenario like this when there is no fallback.
  2. It is possible that new_wh is None. In our case, package_warehouse or application_warehouse could be None if user has not provided that warehouse in their snowflake.yml, config.toml and there is no default warehouse. In that case, the connection context would return a None for this property.
  3. Given the two above, we do need to tackle their nullity accordingly.
    But I am open to hearing if the assumptions in 1 and/or 2 are incorrect and therefore do not need to be handled.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm with Michel, I think we can simplify it as suggested. Sent you a way to determine if warehouse is not set.

Copy link
Contributor

@sfc-gh-cgorrie sfc-gh-cgorrie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My requests: account for None in the project model warehouse properties, and simplify the use warehouse context manager as suggested by Michel.

src/snowflake/cli/plugins/nativeapp/manager.py Outdated Show resolved Hide resolved
if new_wh is not None:
new_wh_id = to_identifier(new_wh)

if prev_wh is None and new_wh is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm with Michel, I think we can simplify it as suggested. Sent you a way to determine if warehouse is not set.

src/snowflake/cli/plugins/nativeapp/project_model.py Outdated Show resolved Hide resolved
src/snowflake/cli/plugins/nativeapp/project_model.py Outdated Show resolved Hide resolved
@sfc-gh-bgoel sfc-gh-bgoel force-pushed the bgoel-regionless-redirect-bugfix branch from 0664030 to 5d9c35d Compare July 11, 2024 13:05
@sfc-gh-bgoel sfc-gh-bgoel enabled auto-merge (squash) July 11, 2024 19:56
Copy link
Contributor

@sfc-gh-cgorrie sfc-gh-cgorrie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sfc-gh-bgoel sfc-gh-bgoel merged commit 50a5b2b into main Jul 15, 2024
16 checks passed
@sfc-gh-bgoel sfc-gh-bgoel deleted the bgoel-regionless-redirect-bugfix branch July 15, 2024 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants