Skip to content

Commit 75b291f

Browse files
authored
Added error handling and tests for Workflow linter during pipeline fetch (#3819)
## Changes Added error handling while fetching pipelines in workflow linting. ### Linked issues Resolves #3815 ### Functionality - [ ] added error handling ### Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [ ] manually tested - [x] added unit tests - [x] added integration tests - [ ] verified on staging environment (screenshot attached)
1 parent c9e6c63 commit 75b291f

File tree

3 files changed

+42
-16
lines changed

3 files changed

+42
-16
lines changed

src/databricks/labs/ucx/source_code/jobs.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from databricks.labs.blueprint.paths import DBFSPath
1212
from databricks.sdk import WorkspaceClient
1313
from databricks.sdk.errors import ResourceDoesNotExist, BadRequest, InvalidParameterValue, DatabricksError
14-
from databricks.sdk.service import compute, jobs
14+
from databricks.sdk.service import compute, jobs, pipelines
1515
from databricks.sdk.service.compute import DataSecurityMode
1616
from databricks.sdk.service.jobs import Source
1717

@@ -286,24 +286,31 @@ def _register_pipeline_task(self, graph: DependencyGraph) -> Iterable[Dependency
286286
if not self._task.pipeline_task:
287287
return
288288

289-
pipeline = self._ws.pipelines.get(self._task.pipeline_task.pipeline_id)
290-
if not pipeline.spec:
289+
try:
290+
pipeline = self._ws.pipelines.get(self._task.pipeline_task.pipeline_id)
291+
except ResourceDoesNotExist:
292+
yield DependencyProblem(
293+
'pipeline-not-found', f'Could not find pipeline: {self._task.pipeline_task.pipeline_id}'
294+
)
291295
return
292-
if not pipeline.spec.libraries:
296+
297+
if not pipeline.spec or not pipeline.spec.libraries:
293298
return
294299

295-
pipeline_libraries = pipeline.spec.libraries
296-
for library in pipeline_libraries:
297-
if not library.notebook:
298-
return
299-
if library.notebook.path:
300-
yield from self._register_notebook_path(graph, library.notebook.path)
301-
if library.jar:
302-
yield from self._register_library(graph, compute.Library(jar=library.jar))
303-
if library.maven:
304-
yield DependencyProblem('not-yet-implemented', 'Maven library is not yet implemented')
305-
if library.file:
306-
yield DependencyProblem('not-yet-implemented', 'File library is not yet implemented')
300+
for library in pipeline.spec.libraries:
301+
yield from self._register_pipeline_library(graph, library)
302+
303+
def _register_pipeline_library(
304+
self, graph: DependencyGraph, library: pipelines.PipelineLibrary
305+
) -> Iterable[DependencyProblem]:
306+
if library.notebook and library.notebook.path:
307+
yield from self._register_notebook_path(graph, library.notebook.path)
308+
if library.jar:
309+
yield from self._register_library(graph, compute.Library(jar=library.jar))
310+
if library.maven:
311+
yield DependencyProblem('not-yet-implemented', 'Maven library is not yet implemented')
312+
if library.file:
313+
yield DependencyProblem('not-yet-implemented', 'File library is not yet implemented')
307314

308315
def _register_notebook_path(self, graph: DependencyGraph, notebook_path: str) -> Iterable[DependencyProblem]:
309316
try:

tests/integration/source_code/test_jobs.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,16 @@ def test_job_dlt_task_linter_unhappy_path(
519519
len([problem for problem in problems if problem.message == "Could not locate import: library_not_found"]) == 1
520520
)
521521

522+
# Pipeline id does not exist
523+
task = jobs.Task(
524+
task_key=make_random(4),
525+
pipeline_task=jobs.PipelineTask(pipeline_id="1234"),
526+
)
527+
j = make_job(tasks=[task])
528+
529+
problems, *_ = simple_ctx.workflow_linter.lint_job(j.job_id)
530+
assert len([problem for problem in problems if problem.message == "Could not find pipeline: 1234"]) == 1
531+
522532

523533
def test_job_dlt_task_linter_happy_path(
524534
simple_ctx,

tests/unit/source_code/test_jobs.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from databricks.labs.ucx.source_code.notebooks.loaders import NotebookLoader, NotebookResolver
3535
from databricks.labs.ucx.source_code.python_libraries import PythonLibraryResolver
3636
from databricks.labs.ucx.source_code.used_table import UsedTablesCrawler
37+
from databricks.sdk.errors.platform import ResourceDoesNotExist
3738

3839

3940
def test_job_problem_as_message() -> None:
@@ -486,6 +487,14 @@ def test_workflow_linter_dlt_pipeline_task(graph) -> None:
486487
assert len(problems) == 4
487488
ws.assert_not_called()
488489

490+
task = jobs.Task(task_key="test", pipeline_task=jobs.PipelineTask(pipeline_id='1234'))
491+
492+
ws.pipelines.get.side_effect = ResourceDoesNotExist("Could not find pipeline: 1234")
493+
494+
workflow_task_container = WorkflowTaskContainer(ws, task, Job())
495+
problems = workflow_task_container.build_dependency_graph(graph)
496+
assert len(problems) == 1
497+
489498

490499
def test_xxx(graph) -> None:
491500
ws = create_autospec(WorkspaceClient)

0 commit comments

Comments
 (0)