This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 8f2cf41538 Fix reraise outside of try block in
`AzureSynapsePipelineRunLink.get_fields_from_url` (#36009)
8f2cf41538 is described below
commit 8f2cf41538d7685e0080a3005b7f68e1115c26bc
Author: Andrey Anshin <[email protected]>
AuthorDate: Fri Dec 1 19:06:07 2023 +0400
Fix reraise outside of try block in
`AzureSynapsePipelineRunLink.get_fields_from_url` (#36009)
---
airflow/providers/microsoft/azure/operators/synapse.py | 6 +++---
tests/providers/microsoft/azure/operators/test_synapse.py | 9 +++++++++
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/airflow/providers/microsoft/azure/operators/synapse.py
b/airflow/providers/microsoft/azure/operators/synapse.py
index f7a23d5f09..f4e0a9954e 100644
--- a/airflow/providers/microsoft/azure/operators/synapse.py
+++ b/airflow/providers/microsoft/azure/operators/synapse.py
@@ -138,14 +138,14 @@ class AzureSynapsePipelineRunLink(BaseOperatorLink):
match = re.search(pattern, workspace_url)
if not match:
- raise ValueError("Invalid workspace URL format")
+ raise ValueError(f"Invalid workspace URL format, expected match
pattern {pattern!r}.")
extracted_text = match.group(1)
parsed_url = urlparse(extracted_text)
path = unquote(parsed_url.path)
path_segments = path.split("/")
- if len(path_segments) < 5:
- raise
+ if (len_path_segments := len(path_segments)) < 5:
+ raise ValueError(f"Workspace expected at least 5 segments, but got
{len_path_segments}.")
return {
"workspace_name": path_segments[-1],
diff --git a/tests/providers/microsoft/azure/operators/test_synapse.py
b/tests/providers/microsoft/azure/operators/test_synapse.py
index 14ffd783ba..9161835982 100644
--- a/tests/providers/microsoft/azure/operators/test_synapse.py
+++ b/tests/providers/microsoft/azure/operators/test_synapse.py
@@ -312,3 +312,12 @@ class TestAzureSynapseRunPipelineOperator:
workspace_name=fields["workspace_name"],
)
)
+
+ def test_pipeline_operator_link_invalid_uri_pattern(self):
+ with pytest.raises(ValueError, match="Invalid workspace URL format"):
+
AzureSynapsePipelineRunLink().get_fields_from_url(workspace_url="https://example.org/")
+
+ def test_pipeline_operator_link_invalid_uri_workspace_segments(self):
+ workspace_url =
"https://web.azuresynapse.net?workspace=%2Fsubscriptions%2Fspam-egg"
+ with pytest.raises(ValueError, match="Workspace expected at least 5
segments"):
+
AzureSynapsePipelineRunLink().get_fields_from_url(workspace_url=workspace_url)