Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions airflow/providers/microsoft/azure/operators/synapse.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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)