Title: Possible bug in exception behaviour of `WhenAllTask` · Issue #33 · microsoft/durabletask-python · GitHub
Open Graph Title: Possible bug in exception behaviour of `WhenAllTask` · Issue #33 · microsoft/durabletask-python
X Title: Possible bug in exception behaviour of `WhenAllTask` · Issue #33 · microsoft/durabletask-python
Description: Just to preface this with I'm coming from using the library in Dapr Workflows. I'm a bit confused with what the intended behaviour should be with the WhenAllTask and what happens when one of the tasks raises an exception. As I'm having t...
Open Graph Description: Just to preface this with I'm coming from using the library in Dapr Workflows. I'm a bit confused with what the intended behaviour should be with the WhenAllTask and what happens when one of the ta...
X Description: Just to preface this with I'm coming from using the library in Dapr Workflows. I'm a bit confused with what the intended behaviour should be with the WhenAllTask and what happens when one o...
Opengraph URL: https://github.com/microsoft/durabletask-python/issues/33
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Possible bug in exception behaviour of `WhenAllTask`","articleBody":"Just to preface this with I'm coming from using the library in Dapr Workflows.\n\nI'm a bit confused with what the intended behaviour should be with the `WhenAllTask` and what happens when one of the tasks raises an exception. As I'm having trouble catching an exception when using `when_all()` - the trouble being I can't.\n\nI've narrowed it down to the fact that there are a couple of instances in this code here:\nhttps://github.com/microsoft/durabletask-python/blob/8598f6b634780bbb8396dbc09ce6515d2f094efd/durabletask/task.py#L276-L302\n\nWhere an Exception is raised directly:\n\n1. https://github.com/microsoft/durabletask-python/blob/8598f6b634780bbb8396dbc09ce6515d2f094efd/durabletask/task.py#L291\n2. https://github.com/microsoft/durabletask-python/blob/8598f6b634780bbb8396dbc09ce6515d2f094efd/durabletask/task.py#L298\n\nNumber 2. is raised as `get_result()` for a task raises an associated exception if present as far as I can see.\n\nWhen either of these are raised directly then the workflow immediately transitions to a `FAILED` status with no chance to catch.\n\nWhile I can see that having the workflow just raise the exception is probably by design, I've come across a use case where I wanted to be able to handle a fan out failure as I need to do a clean up step before failing the workflow.\n\nHowever if you allow for the `_exception` to be set and avoid raising these errors directly with something like:\n\n```python\ndef on_child_completed(self, task: Task[T]):\n if self.is_complete:\n if self._exception is None:\n self._exception = ValueError('The task has already completed.')\n\n self._result = [] # I don't know what this should be\n\n self._completed_tasks += 1\n if task.is_failed and self._exception is None:\n self._failed_tasks += 1\n self._exception = task.get_exception()\n self._is_complete = True\n if self._completed_tasks == len(self._tasks):\n # The order of the result MUST match the order of the tasks provided to the constructor.\n self._result = [task.get_result() if not task.is_failed else task.get_exception() for task in self._tasks]\n self._is_complete = True\n```\n\nI am able to get the behaviour I expect where the workflow task then raises the exception that has been assigned to it and I can catch it and do what I need to do following the failure.\n\nThough I'm not sure about that first `is_complete` check, is it necessary? I'm not sure if all tasks should be allowed to complete and just give the user the choice of whether to have the exception raised or have the exceptions included in the result (a bit like asyncio gather tasks I suppose).\n\nI would be happy to open a PR for this but I'm not sure what would be wanted here?\n","author":{"url":"https://github.com/ajstewart","@type":"Person","name":"ajstewart"},"datePublished":"2024-10-29T10:56:25Z","url":"https://github.com/microsoft/durabletask-python/issues/33"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:950eaaa4-3aa7-4cfe-cef1-81878c29120d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 954A:24FA46:802FF3:ADF5E3:6AFE58AC |
| html-safe-nonce | 47916deb1b944dbef675f49e4aa22c64eb05062c0a85bbb8e5ee46edabb3db36 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NTRBOjI0RkE0Njo4MDJGRjM6QURGNUUzOjZBRkU1OEFDIiwidmlzaXRvcl9pZCI6IjEzNjE0MDU5MTkwOTg3MjI0NzYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f3f5a73402a1a4d42c9319d9ac56b885002378cffe27b902864bad674bd2d7f0 |
| hovercard-subject-tag | issue:2620884750 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/durabletask-python/33/issue_layout |
| twitter:image | https://opengraph.githubassets.com/47723008f046f5a996ac1d238759fd8d5ea0af881b595a44be3572244174e8be/microsoft/durabletask-python/issues/33 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/47723008f046f5a996ac1d238759fd8d5ea0af881b595a44be3572244174e8be/microsoft/durabletask-python/issues/33 |
| og:image:alt | Just to preface this with I'm coming from using the library in Dapr Workflows. I'm a bit confused with what the intended behaviour should be with the WhenAllTask and what happens when one of the ta... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ajstewart |
| hostname | github.com |
| expected-hostname | github.com |
| None | b3c0f155eafc27e60db6e254d1ffff0e072e9ab3b4018a5ee518797c19d89f86 |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/durabletask-python git https://github.com/microsoft/durabletask-python.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 627664515 |
| octolytics-dimension-repository_nwo | microsoft/durabletask-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 627664515 |
| octolytics-dimension-repository_network_root_nwo | microsoft/durabletask-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4a10310af51a1bfffbedc4fd81cb582acf0cb0ff |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width