diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fab07d0794c..de6062437d3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ # See https://pre-commit.com for more information # See https://pre-commit.com/hooks.html for more hooks -exclude: '(^docs/)|flows|examples|scripts|src/promptflow/promptflow/azure/_restclient|src/promptflow/tests/test_configs|src/promptflow-tools' +exclude: '(^docs/)|flows|examples|scripts|src/promptflow/promptflow/azure/_restclient/|src/promptflow/tests/test_configs|src/promptflow-tools' repos: - repo: https://github.com/pre-commit/pre-commit-hooks diff --git a/src/promptflow/promptflow/azure/_restclient/flow_service_caller.py b/src/promptflow/promptflow/azure/_restclient/flow_service_caller.py index 4988e47c179..ef78d5f2beb 100644 --- a/src/promptflow/promptflow/azure/_restclient/flow_service_caller.py +++ b/src/promptflow/promptflow/azure/_restclient/flow_service_caller.py @@ -1,9 +1,6 @@ # --------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. # --------------------------------------------------------- -# --------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# --------------------------------------------------------- """service_calller.py, module for interacting with the AzureML service.""" import json import logging @@ -44,7 +41,7 @@ class RequestTelemetryMixin(TelemetryMixin): def __init__(self): super().__init__() - self._request_id = None + self._request_id = str(uuid.uuid4()) self._from_cli = False def _get_telemetry_values(self, *args, **kwargs): @@ -126,10 +123,7 @@ def __init__(self, workspace, credential, base_url=None, region=None, **kwargs): def _get_headers(self): token = self._credential.get_token("https://management.azure.com/.default") - custom_header = { - "Authorization": "Bearer " + token.token, - "x-ms-client-request-id": str(uuid.uuid4()) - } + custom_header = {"Authorization": "Bearer " + token.token, "x-ms-client-request-id": self._request_id} return custom_header def _set_headers_with_user_aml_token(self, headers): diff --git a/src/promptflow/tests/sdk_cli_azure_test/e2etests/test_run_operations.py b/src/promptflow/tests/sdk_cli_azure_test/e2etests/test_run_operations.py index f26f95175dc..fa98392095c 100644 --- a/src/promptflow/tests/sdk_cli_azure_test/e2etests/test_run_operations.py +++ b/src/promptflow/tests/sdk_cli_azure_test/e2etests/test_run_operations.py @@ -543,17 +543,15 @@ def submit(*args, **kwargs): data=f"{DATAS_DIR}/env_var_names.jsonl", ) - @pytest.mark.skip(reason="server-side error.") def test_automatic_runtime_creation_failure(self, pf): with pytest.raises(FlowRequestException) as e: pf.runs._resolve_runtime( run=Run( - flow=Path(f"{FLOWS_DIR}/flow_with_environment"), - data=f"{DATAS_DIR}/env_var_names.jsonl", + flow=Path(f"{FLOWS_DIR}/basic-with-connection"), resources={"instance_type": "not_exist"}, ), - flow_path=Path(f"{FLOWS_DIR}/flow_with_environment"), + flow_path=Path(f"{FLOWS_DIR}/basic-with-connection"), runtime=None, ) assert "Session creation failed for" in str(e.value) @@ -563,10 +561,17 @@ def test_run_submission_exception(self, remote_client): from promptflow.azure._restclient.flow.operations import BulkRunsOperations + def fake_submit(*args, **kwargs): + headers = kwargs.get("headers", None) + request_id_in_headers = headers["x-ms-client-request-id"] + # request id in headers should be same with request id in service caller + assert request_id_in_headers == remote_client.runs._service_caller._request_id + raise HttpResponseError("customized error message.") + with patch.object(BulkRunsOperations, "submit_bulk_run") as mock_request, patch.object( FlowServiceCaller, "_set_headers_with_user_aml_token" ): - mock_request.side_effect = HttpResponseError("customized error message.") + mock_request.side_effect = fake_submit with pytest.raises(FlowRequestException) as e: original_request_id = remote_client.runs._service_caller._request_id remote_client.runs._service_caller.submit_bulk_run(