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

Defer fetching role and warehouse until they're needed #1631

Merged
merged 1 commit into from
Sep 27, 2024

Conversation

sfc-gh-fcampbell
Copy link
Contributor

@sfc-gh-fcampbell sfc-gh-fcampbell commented Sep 26, 2024

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

We have some commands, like snow app bundle/snow ws bundle that don't even need a connection, so let's defer connecting to Snowflake until it's actually needed by the particular action being run.

For now, all snow ws commands are still marked as requiring a connection, that will be fixed separately.

if cli_context.connection.warehouse:
self.default_warehouse = to_identifier(cli_context.connection.warehouse)
self._default_role = self._UNSET
self._default_warehouse = self._UNSET
Copy link
Contributor Author

Choose a reason for hiding this comment

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

self.default_warehouse wasn't used externally, so it's safe to change it to self._default_warehouse

@sfc-gh-fcampbell sfc-gh-fcampbell marked this pull request as ready for review September 27, 2024 11:39
@sfc-gh-fcampbell sfc-gh-fcampbell force-pushed the frank-defer-role-warehouse branch 2 times, most recently from fe74040 to c09aaa6 Compare September 27, 2024 11:45
self._default_role = self._UNSET
self._default_warehouse = self._UNSET

def _get_default_role(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: could you add a return type annotation? I think it's important here to label whether the return value is optional or not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 47 to 53
if self._default_warehouse is self._UNSET:
cli_context = get_cli_context()
if cli_context.connection.warehouse:
self._default_warehouse = to_identifier(
cli_context.connection.warehouse
)
return self._default_warehouse
Copy link
Contributor

Choose a reason for hiding this comment

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

there is no connection warehouse, isn't this going to return UNSET? That doesn't sound right. The role logic doesn't have this issue because if assigns None even if the fallback logic fails to produce a valid role.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sfc-gh-bdufour good catch, I updated the implementation to use @cached_property in the ActionContext since we don't need to be caching them in WorkspaceManager

@sfc-gh-fcampbell sfc-gh-fcampbell force-pushed the frank-defer-role-warehouse branch 2 times, most recently from e8a07c1 to 06d701a Compare September 27, 2024 13:17
@sfc-gh-fcampbell sfc-gh-fcampbell enabled auto-merge (squash) September 27, 2024 13:22
@sfc-gh-fcampbell sfc-gh-fcampbell merged commit 553f645 into main Sep 27, 2024
21 checks passed
@sfc-gh-fcampbell sfc-gh-fcampbell deleted the frank-defer-role-warehouse branch September 27, 2024 13:47
sfc-gh-sichen pushed a commit that referenced this pull request Oct 17, 2024
We have some commands, like `snow app bundle`/`snow ws bundle` that don't even need a connection, so let's defer connecting to Snowflake until it's actually needed by the particular action being run.

For now, all `snow ws` commands are still marked as requiring a connection, that will be fixed separately.
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.

2 participants