Closed Holi0317 closed 1 year ago
This is expected, in all exception based SDKs (like python) only Temporal Errors fail a Workflow Execution by default, other exceptions will retry the Workflow Task. You can use ApplicationError in the Python SDK to fail the workflow.
This is also in our documentation https://docs.temporal.io/references/failures#throw-from-workflows
:+1: To what @Quinn-With-Two-Ns said. Closing, but feel free to continue conversation here or on #python-sdk
Slack or in the forums.
What are you really trying to do?
I am trying to raise an exception inside workflow which should cause the workflow to fail.
Describe the bug
In the official concept documentation, the expected default behavior of retry on workflow is:
I try to raise an
RuntimeError
, or actually just aValueError
will cause this problem where python sdk raise "Failed activation on workflow" and retries the workflow indefinitely.Minimal Reproduction
Python
```python import asyncio import logging from temporalio import workflow from temporalio.client import Client, WorkflowFailureError from temporalio.worker import Worker @workflow.defn class GreetingWorkflow: @workflow.run async def run(self, name: str) -> str: raise RuntimeError("Goodbye world") return "" async def main(): # Start client client = await Client.connect("localhost:7233") # Run a worker for the workflow async with Worker( client, task_queue="hello-exception-task-queue", workflows=[GreetingWorkflow], ): # While the worker is running, use the client to run the workflow and # print out its result. Note, in many production setups, the client # would be in a completely separate process from the worker. # # This will raise a WorkflowFailureError with cause ActivityError with # cause ApplicationError with the error message and stack trace. try: await client.execute_workflow( GreetingWorkflow.run, "World", id="hello-exception-workflow-id", task_queue="hello-exception-task-queue", ) except WorkflowFailureError: # Log the exception logging.exception("Got workflow failure") if __name__ == "__main__": asyncio.run(main()) ```It fails with following stacktrace:
And temporal UI showing the workflow is "running", not "Failed"
I did try to replicate this issue with go and the temporal workflow stopped correctly there:
Go implementation
```go package main import ( "context" "fmt" "log" "time" "go.temporal.io/sdk/client" "go.temporal.io/sdk/worker" "go.temporal.io/sdk/workflow" ) // Workflow is a Hello World workflow definition. func Workflow(ctx workflow.Context, name string) (string, error) { ao := workflow.ActivityOptions{ StartToCloseTimeout: 10 * time.Second, } ctx = workflow.WithActivityOptions(ctx, ao) logger := workflow.GetLogger(ctx) logger.Info("HelloWorld workflow started", "name", name) return "", fmt.Errorf("Goodbye world") } func workerMain() { // The client and worker are heavyweight objects that should be created once per process. c, err := client.Dial(client.Options{}) if err != nil { log.Fatalln("Unable to create client", err) } defer c.Close() w := worker.New(c, "hello-world", worker.Options{}) w.RegisterWorkflow(Workflow) err = w.Run(worker.InterruptCh()) if err != nil { log.Fatalln("Unable to start worker", err) } } func main() { go workerMain() // The client is a heavyweight object that should be created once per process. c, err := client.Dial(client.Options{}) if err != nil { log.Fatalln("Unable to create client", err) } defer c.Close() workflowOptions := client.StartWorkflowOptions{ ID: "hello_world_workflowID", TaskQueue: "hello-world", } we, err := c.ExecuteWorkflow(context.Background(), workflowOptions, Workflow, "Temporal") if err != nil { log.Fatalln("Unable to execute workflow", err) } log.Println("Started workflow", "WorkflowID", we.GetID(), "RunID", we.GetRunID()) // Synchronously wait for the workflow completion. var result string err = we.Get(context.Background(), &result) if err != nil { log.Fatalln("Unable get workflow result", err) } log.Println("Workflow result:", result) } ```Output of the go version is:
Environment/Versions
temporal
cli from brewAdditional context
I did found https://github.com/temporalio/sdk-python/pull/329 which seems related to this issue.