-
Notifications
You must be signed in to change notification settings - Fork 54
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
SNOW-1706990 Extract non action-related fields in ActionContext to new WorkspaceContext #1652
Conversation
65bd816
to
828e782
Compare
Hmm, not sure about this one yet. It made sense to me to decouple the entity model from the action state, but this couples them again. Can you give me specifics about why we want to access things like |
I'm trying to get rid of Right now, for an operation like def get_existing_app_info(self) -> Optional[dict]:
return ApplicationEntity.get_existing_app_info(
app_name=self.app_name,
app_role=self.app_role,
) @staticmethod
def get_existing_app_info(app_name: str, app_role: str) -> Optional[dict]:
sql_executor = get_sql_executor()
with sql_executor.use_role(app_role):
return sql_executor.show_specific_object(
"applications", app_name, name_col=NAME_COL
) In The problem I'm facing now is that My solution to this is to set the def get_existing_app_info(self) -> Optional[dict]:
model = self._entity_model
ctx = self._action_ctx
role = (model.meta and model.meta.role) or ctx.default_role # default_role used here
sql_executor = get_sql_executor()
with sql_executor.use_role(role):
return sql_executor.show_specific_object(
"applications", model.fqn.name, name_col=NAME_COL
) and could be called without needing the whole app = ws.get_entity(app_id)
if app.get_existing_app_info():
typer.launch(app.get_snowsight_url())
return MessageResult(f"Snowflake Native App opened in browser.")
else:
return MessageResult(
'Snowflake Native App not yet deployed! Please run "snow app run" first.'
) |
Pull request was converted to draft
828e782
to
a0865de
Compare
get_entity=self.get_entity, | ||
) | ||
return entity.perform(action, action_ctx, *args, **kwargs) | ||
else: | ||
raise ValueError(f'This entity type does not support "{action.value}"') | ||
|
||
@property |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drive-by improvement, we never take a reference to this method so it can be a property instead, like it is in other classes
e685a5e
to
04f8641
Compare
04f8641
to
f3213f4
Compare
Description of changes after that long post above. A previous version of this PR was passing the whole |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this - the first time I read ActionContext
I was wondering why things like get_default_role
and get_default_warehouse
are action context. This makes more sense :)
""" | ||
An object that is passed to each action when called by WorkspaceManager | ||
An object that is passed to each entity when instantiated by WorkspaceManager | ||
to allow access to the CLI context without required the entities to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"without requiring"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
…ntext, which is stored as instance field on entities
f3213f4
to
d3d659f
Compare
…w WorkspaceContext (#1652) Entity classes current have lots of static methods, which were added to support the v1 to v2 migration, but they have way too many parameters, so we want to allow calling these methods on entity instances. Right now, the only instance methods are `EntityAction` implementations, which represent the top-level actions that can be performed by these entities, but the static methods we want to convert to instance methods don't need to be `EntityAction` implementations (since they don't represent top-level operations). However, it would be useful for these methods to have access to utilities in the `ActionContext`, like `ctx.default_role` for example. Since these utilities are not really part of the action, let's extract them from `ActionContext` into a new `WorkspaceContext` that gets set as a field of the entity when instantiated by the `WorkspaceManager`.
Pre-review checklist
Changes description
Entity classes current have lots of static methods, which were added to support the v1 to v2 migration, but they have way too many parameters, so we want to allow calling these methods on entity instances.
Right now, the only instance methods are
EntityAction
implementations, which represent the top-level actions that can be performed by these entities, but the static methods we want to convert to instance methods don't need to beEntityAction
implementations (since they don't represent top-level operations). However, it would be useful for these methods to have access to utilities in theActionContext
, likectx.default_role
for example. Since these utilities are not really part of the action, let's extract them fromActionContext
into a newWorkspaceContext
that gets set as a field of the entity when instantiated by theWorkspaceManager
.