nice-baker-83329
09/29/2025, 8:51 AM# Get current execution context to check retry attempt
ctx = fl.current_context()
current_attempt = getattr(ctx.execution_state, 'retries', 0) + 1
but its not working. How can I store a value between task tries and set a custom logic based on its value ?ancient-wolf-19325
09/29/2025, 8:51 AMnice-baker-83329
09/29/2025, 8:53 AMnice-baker-83329
09/29/2025, 8:54 AMancient-wolf-19325
09/29/2025, 8:54 AMfrom flytekit import task, current_context
@task(retries=3)
def my_task():
attempt = current_context().execution_state.attempt_number
print(f"Current attempt: {attempt}")
# Your custom logic here
This will print the current retry attempt each time the task is retried. For more details, see the Flyte intratask checkpointing documentation.
Would you like a more advanced example, such as combining this with checkpointing or custom retry logic?
Sources:
- Flyte intratask checkpointing documentation 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.nice-baker-83329
09/29/2025, 9:01 AMcurrent_attempt = ctx.execution_state.attempt_number\n ^^^^^^^^^^^^^^^^^^^\n File \ │
│ "/opt/venv/lib/python3.12/site-packages/flytekit/core/context_manager.py\", line 330, in __getattr__\n raise AssertionError(f\"{attr_name} not available as a parameter in Flyte context - │
│ are you in right task-type?\")\n AssertionError: EXECUTION_STATE not available as a parameter in Flyte context - are you in right task-type?\n\nMessage:\n\n AssertionError: EXECUTION_STATE │
│ not available as a parameter in Flyte context - are you in right task-type?"}ancient-wolf-19325
09/29/2025, 9:01 AMnice-baker-83329
09/29/2025, 9:06 AM│ An unexpected error occurred: EXECUTION_STATE not available as a parameter in Flyte context - are you in right task-type? │ancient-wolf-19325
09/29/2025, 9:06 AM