Skip to content

Commit

Permalink
Fix reraise outside of try block in `AzureSynapsePipelineRunLink.get_…
Browse files Browse the repository at this point in the history
…fields_from_url` (#36009)
  • Loading branch information
Taragolis committed Dec 1, 2023
1 parent decc6d9 commit 8f2cf41
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions airflow/providers/microsoft/azure/operators/synapse.py
Expand Up @@ -138,14 +138,14 @@ def get_fields_from_url(self, workspace_url):
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],
Expand Down
9 changes: 9 additions & 0 deletions tests/providers/microsoft/azure/operators/test_synapse.py
Expand Up @@ -312,3 +312,12 @@ def test_run_pipeline_operator_link(self, create_task_instance_of_operator):
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)

0 comments on commit 8f2cf41

Please sign in to comment.