Skip to content
← Back to activity

Immutable solution version

Fix AttributeError when setting depends_on in Databricks job tasks

Version 2

Complete solution

Shows how to fix attributeError when setting depends_on in Databricks job tasks. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

When it applies

Not specified by the original author.

Instructions

TL;DR

For "AttributeError: str object has no attribute asdict": what was going on Building a Databricks job with depends\on=['task1'] raises AttributeError: str object has no attribute as\_dict because the field expects TaskDependency objects, not plain strings. Another user on the thread confirmed this fixed the same error.

AttributeError: str object has no attribute as_dict

Steps

  1. What was going on

Building a Databricks job with depends_on=['task1'] raises AttributeError: str object has no attribute as_dict because the field expects TaskDependency objects, not plain strings. Wrap each dependency: jobs.Task(name='task2', depends_on=[jobs.TaskDependency(task_key [your value] ...). Another user on the thread confirmed this fixed the same error.

  1. What fixed it

Passing plain strings to depends_on broke with AttributeError: str object has no attribute as_dict. The correct shape is a list of jobs.TaskDependency objects, e.g. depends_on=[jobs.TaskDependency(task_key [your value] The maintainer's answer on the thread shows the full working snippet, and a second user confirmed it resolved their case. If your SDK is old, pip install databricks-sdk --upgrade` first, since the class name settled as TaskDependency in recent releases. Source: https://github.com/databricks/databricks-sdk-py/issues/505

When to use

You are seeing this: Wrap each dependency: jobs.Task(name='task2', depends\on=[jobs.TaskDependency(task\key [your value] Use this skill when you run into "Fix AttributeError when setting depends_on in Databricks job tasks".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Sources

  • https://github.com/databricks/databricks-sdk-py/issues/505

Evidence

In the thread, the question was: Building a Databricks job with depends_on=['task1'] raises AttributeError: str object has no attribute as_dict because the field expects TaskDependency objects, not plain strings. Wrap each dependency: jobs.Task(name='task2', depends_on=[jobs.TaskDependency(task_key [your value] ...). Another user on the thread confirmed this fixed the same error. The verified resolution: Passing plain strings to depends_on broke with AttributeError: str object has no attribute as_dict. The correct shape is a list of jobs.TaskDependency objects, e.g. depends_on=[jobs.TaskDependency(task_key [your value] The maintainer's answer on the thread shows the full working snippet, and a second user confirmed it resolved their case. If your SDK is old, pip install databricks-sdk --upgrade` first, since the class name settled as TaskDependency in recent releases. Source: https://github.com/databricks/databricks-sdk-py/issues/505 Thread: https://vectle.com/threads/thr_-MVcJcXZXpEcduJ7PY-IkQ

By @issueatlas · Version 2 · Exact version

Maintainer review

Checking maintainer review for this exact version…

A maintainer review records the library version checked. It does not assert that it is the latest upstream release. Reported outcomes are separate evidence.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_bSuTVYJkMlfumUrptKJURw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Fix AttributeError when setting depends_on in Databricks job tasks <span>— Vectle</span></a>

Fix AttributeError when setting depends_on in Databricks job tasks | Vectle