Skip to content

Commit

Permalink
[Connection] Remove workspace resource check as it requires Workspace…
Browse files Browse the repository at this point in the history
…/Read (#2957)

# Description

Please add an informative description that covers that changes made by
the pull request and link all relevant issues.
Side effect pr: #2751 

# All Promptflow Contribution checklist:
- [ ] **The pull request does not introduce [breaking changes].**
- [ ] **CHANGELOG is updated for new features, bug fixes or other
significant changes.**
- [ ] **I have read the [contribution guidelines](../CONTRIBUTING.md).**
- [ ] **Create an issue and link to the pull request to get dedicated
review from promptflow team. Learn more: [suggested
workflow](../CONTRIBUTING.md#suggested-workflow).**

## General Guidelines and Best Practices
- [ ] Title of the pull request is clear and informative.
- [ ] There are a small number of commits, each of which have an
informative message. This means that previously merged commits do not
appear in the history of the PR. For more information on cleaning up the
commits in your PR, [see this
page](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md).

### Testing Guidelines
- [ ] Pull request includes test coverage for the included changes.

Signed-off-by: Brynn Yin <[email protected]>
  • Loading branch information
brynn-code authored Apr 23, 2024
1 parent 8e523e4 commit 12f93f9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 32 deletions.
15 changes: 2 additions & 13 deletions src/promptflow-core/promptflow/core/_connection_provider/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# ---------------------------------------------------------
import os

from promptflow._constants import PF_NO_INTERACTIVE_LOGIN, AzureWorkspaceKind
from promptflow._constants import PF_NO_INTERACTIVE_LOGIN
from promptflow._utils.user_agent_utils import ClientUserAgentUtil
from promptflow.core._errors import MissingRequiredPackage, UnsupportedWorkspaceKind
from promptflow.core._errors import MissingRequiredPackage
from promptflow.exceptions import ValidationException


Expand Down Expand Up @@ -67,14 +67,3 @@ def interactive_credential_disabled():
def is_from_cli():
"""Check if the current execution is from promptflow-cli."""
return "promptflow-cli" in ClientUserAgentUtil.get_user_agent()


def check_connection_provider_resource(resource_id: str, credential, pkg_name):
from .._utils import get_workspace_from_resource_id

workspace = get_workspace_from_resource_id(resource_id, credential, pkg_name)
if workspace._kind not in [AzureWorkspaceKind.DEFAULT, AzureWorkspaceKind.PROJECT]:
raise UnsupportedWorkspaceKind(
message=f"Workspace kind {workspace._kind!r} is not supported. "
f"Please use either an azure machine learning workspace or an azure ai project."
)
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@

from ..._utils.credential_utils import get_default_azure_credential
from ._connection_provider import ConnectionProvider
from ._utils import (
check_connection_provider_resource,
interactive_credential_disabled,
is_from_cli,
is_github_codespaces,
)
from ._utils import interactive_credential_disabled, is_from_cli, is_github_codespaces

GET_CONNECTION_URL = (
"/subscriptions/{sub}/resourcegroups/{rg}/providers/Microsoft.MachineLearningServices"
Expand Down Expand Up @@ -86,7 +81,6 @@ def __init__(
self.resource_id = AML_WORKSPACE_TEMPLATE.format(
self.subscription_id, self.resource_group_name, self.workspace_name
)
self._workspace_checked = False

@property
def credential(self):
Expand Down Expand Up @@ -441,12 +435,6 @@ def _build_list_connection_dict(
return rest_list_connection_dict

def list(self) -> List[_Connection]:
if not self._workspace_checked:
# Check workspace not 'hub'
check_connection_provider_resource(
resource_id=self.resource_id, credential=self.credential, pkg_name="promptflow-core[azureml-serving]"
)
self._workspace_checked = True
rest_list_connection_dict = self._build_list_connection_dict(
subscription_id=self.subscription_id,
resource_group_name=self.resource_group_name,
Expand All @@ -462,12 +450,6 @@ def list(self) -> List[_Connection]:
return connection_list

def get(self, name: str, **kwargs) -> _Connection:
if not self._workspace_checked:
# Check workspace not 'hub'
check_connection_provider_resource(
resource_id=self.resource_id, credential=self.credential, pkg_name="promptflow-core[azureml-serving]"
)
self._workspace_checked = True
connection_dict = self._build_connection_dict(
name,
subscription_id=self.subscription_id,
Expand Down

0 comments on commit 12f93f9

Please sign in to comment.