question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Upstream tasks issue with Task.map

See original GitHub issue

Description

I’m encountering a bug that feels related to #2430 that was fixed in master. When an upstream_tasks parameter is provided to a Task.map function and the upstream task errors I get the following:

TypeError: Cannot map over unsubscriptable object of type <class 'prefect.engine.signals.TRIGGERFAIL'>: TRIGGERFAI...

There is no issue as long as the upstream task does not fail.

Expected Behavior

Expected the map function to behave similar to an unmapped function in this case.

Reproduction

from typing import List, Dict
from prefect import Flow
from prefect import Task
from prefect.triggers import any_failed


class TaskA(Task):
    def run(self) -> List[Dict]:
        records = [
            {"data": "dummy"},
            {"data": "dummier"},
            {"data": "dummiest"},
        ]
        return records


class TaskB(Task):
    def run(self) -> None:
        print("doing something unrelated")


class TaskC(Task):
    def run(self, data: List) -> None:
        raise RuntimeError("Uncomment this to fix")
        print(f"Data: {data}")


class TaskD(Task):
    def run(self, data: List) -> None:
        print("Cleaning up failure")


task_a = TaskA()
task_b = TaskB()
task_c = TaskC()
task_d = TaskD(trigger=any_failed)

# Create dummy flow
with Flow("dummy_flow") as flow:
    data = task_a()
    task_b_slug = task_b().slug
    task_c_slug = task_c.map(
        data=data, upstream_tasks=[flow.get_tasks(slug=task_b_slug)]
    ).slug
    task_d.map(data=data, upstream_tasks=[flow.get_tasks(slug=task_c_slug)])

flow.run()

Environment

I tested this in 0.11.5 and master and seems to be the same bahaviour.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jacques-commented, Jun 15, 2020

Ok, I think I’m following this now. Using imperative API has solved this for us.

I think we are going to be converting the rest of our flows to imperative API.

Thanks so much for taking the time to walk me through this, it is really appreciated!

P.S. I see now that https://docs.prefect.io/core/concepts/flows.html#apis talks about the more fine grained control you get from the imperative API - I didn’t catch why/when that would be useful when I read those docs originally but def do now!

0reactions
joshmeekcommented, Jun 15, 2020

@jacques- Glad it’s solved! Don’t hesitate to reach out with issues here or more questions on Slack if something comes up.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic Task Mapping — Airflow Documentation
Dynamic Task Mapping allows a way for a workflow to create a number of tasks at runtime based upon current data, rather than...
Read more >
Mapping | Prefect Docs
This means that a mapped task can depend on both mapped and reduced upstream tasks seamlessly. TIP. Prefect also provides a mapped() annotation...
Read more >
Task upstream of branch gets skipped for no reason -- Airflow ...
This happens during every scheduled run, and I have to manually clear out all the tasks every time to get them all to...
Read more >
Create dynamic Airflow tasks | Astronomer Documentation
Dynamic task concepts​ · You can use the results of an upstream task as the input to a mapped task. · You can...
Read more >
Top Features in the Airflow 2.3 Release - Six Feet Up
Dynamic Task Mapping · In the new Grid View, dynamic tasks appear as a single task but their name is appended with a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found