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.

Trigger failure in Task.map

See original GitHub issue

Description

Triggers don’t seem to call when passed to a .map() Task. Instead the .map() seems to try and process the exception value instead.

Expected Behavior

Expect the trigger to function in the same way as for non-map Task.

Reproduction

from typing import List, Dict
from prefect import Flow
from prefect import Task
from prefect.engine.cache_validators import all_parameters
from prefect.triggers import all_successful


class ExtractDummyTask(Task):
    def run(self) -> List[Dict]:
        records = [
            {"data": "dummy"},
            {"data": "dummier"},
            {"data": "dummiest"},
        ]
        raise RuntimeError("my test error")
        return records


class TransformDummyTask(Task):
    def run(self, data: List) -> List:
        return data


class LoadDummyTask(Task):
    def run(self, data: List) -> None:
        print(f"Data: {data}")


extract_dummy = ExtractDummyTask(trigger=all_successful)
transform_dummy = TransformDummyTask(trigger=all_successful)
load_dummy = LoadDummyTask(trigger=all_successful)

# Create dummy flow
with Flow("dummy_flow") as flow:
    # Extract
    values = extract_dummy(
    )

    # Transform
    # transformed_values = transform_dummy(data=values) # This works as expected
    transformed_values = transform_dummy.map(data=values)

    # Load
    load_dummy(data=transformed_values)

flow.run()

Environment

Tried this locally on mac as well as local dask - same behaviour in both.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
andywaughcommented, Jun 4, 2020

Hey @cicdw - thanks for the swift reply. Yep, have just re-run against master and it seems the refactor has indeed resolved the issue.

1reaction
cicdwcommented, May 1, 2020

This is definitely a bug, but for anyone reading along at home I’d like to provide some context for why this was originally implemented as intentional behavior: if a user writes a multi-level mapped Flow such as:

from prefect import task, Flow

@task
def return_stuff():
    return [0, 1, 2]

@task
def divide(x):
    return 1 / x

@task
def subtract(y):
    return y - 1

with Flow("multi-level mapping") as flow:
    final = subtract.map(divide.map(return_stuff))

flow_state = flow.run()

print(flow_state.result[final].map_states)

# [<TriggerFailed: "Trigger was "all_successful" but some of the upstream tasks failed.">,
#  <Success: "Task run succeeded.">,
#  <Success: "Task run succeeded.">]

Note that the second level of mapped tasks ran, and some even succeeded; this is only possible because each child task was allowed to check its own trigger. If the parent had checked the trigger, it would have decided that the second level of mapped tasks was not ready to proceed (because there was an upstream failure).

The trick will be to figure out a way to fix the bug here + still satisfy this multi-level situation

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is my task trigger test failing - Salesforce Stack Exchange
I have a task trigger which updates two custom fields on the Account object : Last_Call_Date and Last_Meeting_Date. I have tried logging a...
Read more >
Scheduled Task repeated trigger failure with a managed ...
I have set up a scheduled task on Windows Server 2012 R2 Standard, and it's failing ONLY when I set the trigger to...
Read more >
Airflow Trigger Rules: All you need to know! - Marc Lamberti
With this simple trigger rule, your task gets triggered if no upstream tasks are skipped. If they are all in success or failed....
Read more >
Mapping | Prefect Docs
If a reducing task has an all_successful task, but one of the mapped children failed, then the reducing task's trigger will fail. This...
Read more >
How to inspect mapped tasks' inputs from reduce tasks in Prefect
The handling will largely happen in the persist_episodes . Just pass the list of inputs again and then we can match the inputs...
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