Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Allow string as exceptions in on_failure_callback #695

Merged
merged 1 commit into from Sep 2, 2022

Conversation

AetherUnbound
Copy link
Contributor

Fixes

Fixes WordPress/openverse#1453 by @AetherUnbound

Description

This PR allows strings to be passed in as the exception to an on_failure_callback.

See WordPress/openverse#1453 for a longer description of the problem.

Testing Instructions

just test

Optionally attempt to fail a provider pull media task locally. You should see the failure callback still logged (instead of an exception). Here's an example, with extra logging added at the beginning to emphasise what was handed in:

[2022-08-24, 03:43:25 UTC] {slack.py:308} ERROR - exception='task marked as failed externally' type(exception)=<class 'str'>
[2022-08-24, 03:43:25 UTC] {slack.py:227} INFO - 
*DAG*: `cleveland_museum_workflow`
*Task*: `pull_image_data`
*Execution Date*: 2022-07-01T00:00:00Z
*Log*: http://localhost:8080/log?execution_date=2022-07-01T00%3A00%3A00%2B00%3A00&task_id=pull_image_data&dag_id=cleveland_museum_workflow&map_index=-1

*Exception*: task marked as failed externally
*Exception Type*: `builtins.str`

[2022-08-24, 03:43:25 UTC] {base.py:68} INFO - Using connection ID 'slack_alerts' for task execution.

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@AetherUnbound AetherUnbound requested a review from a team as a code owner August 24, 2022 03:55
@openverse-bot openverse-bot added this to Needs review in Openverse PRs Aug 24, 2022
@AetherUnbound AetherUnbound changed the title Allow string as exceptions in on_failure_callback Allow string as exceptions in on_failure_callback Aug 24, 2022
@openverse-bot openverse-bot added 💻 aspect: code Concerns the software code in the repository 🛠 goal: fix Bug fix 🟩 priority: low Low priority and doesn't need to be rushed labels Aug 24, 2022
Copy link
Contributor

@stacimc stacimc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, this cleans things up considerably 😄

Completely out of curiosity, are you able to reproduce the Upstream task(s) failed exception handling? I've tried raising an error in copy_to_s3 for example, which causes load_from_s3 to enter the upstream_failed state, but there's no log file at all for the task. From the docs (and I was even curious enough to check the source) it clearly fires the callback in this state so this check definitely should be necessary to prevent Slack messages from all downstream failures.

@AetherUnbound
Copy link
Contributor Author

Completely out of curiosity, are you able to reproduce the Upstream task(s) failed exception handling? I've tried raising an error in copy_to_s3 for example, which causes load_from_s3 to enter the upstream_failed state, but there's no log file at all for the task. From the docs (and I was even curious enough to check the source) it clearly fires the callback in this state so this check definitely should be necessary to prevent Slack messages from all downstream failures.

Admittedly, this was some code I had where I was interacting with an older version of Airflow 😅 It's possible this interaction has changed or may just not be necessary at all 🤔 It's also possible this callback is being run on the scheduler rather than a whole worker being spun up just to handle the callback. I'll try and see where this is happening.

@AetherUnbound
Copy link
Contributor Author

Okay I've poked around a bit - I thought perhaps that the logs for callbacks on the upstream task failed tasks could be found in the scheduler logs or something, but I can't find them anywhere. The Airflow source code is a bit hard to pull apart in these cases, so it's hard to know if it's even being called, honestly! I'll leave it as-is for now though, it doesn't hurt to have.

@stacimc
Copy link
Contributor

stacimc commented Aug 31, 2022

@AetherUnbound thanks for humoring me! Definitely not a concern for the PR, but an interesting mystery 😄

Copy link
Member

@zackkrida zackkrida left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see the failure callback still logged

I indeed did! LGTM.

Openverse PRs automation moved this from Needs review to Reviewer approved Sep 2, 2022
Copy link
Contributor

@obulat obulat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@AetherUnbound AetherUnbound merged commit 25feeb7 into main Sep 2, 2022
Openverse PRs automation moved this from Reviewer approved to Merged! Sep 2, 2022
@AetherUnbound AetherUnbound deleted the bugfix/failed-failure-callback#693 branch September 2, 2022 18:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
💻 aspect: code Concerns the software code in the repository 🛠 goal: fix Bug fix 🟩 priority: low Low priority and doesn't need to be rushed
Projects
No open projects
Openverse PRs
  
Merged!
Development

Successfully merging this pull request may close these issues.

Exception in on failure callback may not be of type Exception
5 participants