<#4999 [BUG] Cannot use `on_failure` with a task t...
# flytekit
c
#4999 [BUG] Cannot use `on_failure` with a task that uses secrets Issue created by lindseynield ### Describe the bug When I register a workflow that uses
on_failure
to call a task that uses secret requests, I get an error that
Failed with Unknown Exception <class 'ValueError'> Reason: Please make sure to add secret_requests=[Secret(group=<group>, key=<key>)] in @task. Unable to find secret for key token in group secret in Env Var:_FSEC_SECRET_TOKEN and FilePath: <path>
even though this exact
secret_requests
is already in the
@task
. The secret does exist, and can be successfully requested in a task that is called in the workflow, but it fails when the task is called in
on_failure
### Expected behavior
on_failure
can call a task with secret injection as long as
secret_requests
is in the
@task
### Additional context to reproduce Using a secret that exists at
secret/token
Copy code
from flytekit import Secret, task, workflow, current_context
from pytest import fail


@task(secret_requests=[Secret(group="secret", key="token")])
def on_failure_task() -> None:
    token = current_context().secrets.get("secret", "token")


@task
def fail_task() -> None:
    fail("This task is supposed to fail")


@workflow(on_failure=on_failure_task())
def fail_workflow() -> None:
    fail_task()
Results in:
Failed with Unknown Exception <class 'ValueError'> Reason: Please make sure to add secret_requests=[Secret(group=secret, key=token)] in @task. Unable to find secret for key token in group secret in Env Var:_FSEC_SECRET_TOKEN and FilePath: secret/token
Whereas this is valid:
Copy code
from flytekit import Secret, task, workflow, current_context
from pytest import fail


@task(secret_requests=[Secret(group="secret", key="token")])
def on_failure_task() -> None:
    token = current_context().secrets.get("secret", "token")

@workflow
def fail_workflow() -> None:
    on_failure_task()
### Screenshots No response ### Are you sure this issue hasn't been raised already? • Yes ### Have you read the Code of Conduct? • Yes flyteorg/flyte