Emil Christensen
07/06/2023, 3:34 PMfrom prefect import flow, get_run_logger
from prefect.context import get_run_context
@flow(retries=3)
def main():
get_run_logger().warning(f"This is run {get_run_context().flow_run.run_count}")
raise ValueError()
if __name__ == "__main__":
main()
dainslie
07/06/2023, 3:35 PMTheo Platt
07/06/2023, 3:38 PMFile "/Users/theoplatt/git/prefectcourse/pacc102.py", line 9, in try_again
log.warning(f"This is run {get_run_context().flow_run.run_count}")
^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'TaskRunContext' object has no attribute 'flow_run'
dainslie
07/06/2023, 3:41 PMTheo Platt
07/06/2023, 3:42 PMget_run_context().task_run.run_count
task_run
not flow_run
when in a taskdainslie
07/06/2023, 3:44 PMCount = $1
Theo Platt
07/06/2023, 3:45 PMlog = get_run_logger()
log.warning(f"This is run {get_run_context().task_run.run_count}")
16:42:36.024 | WARNING | Task run 'try_again-0' - This is run 2
16:42:36.549 | INFO | Task run 'try_again-0' - Failed
16:42:36.550 | ERROR | Task run 'try_again-0' - Encountered exception during execution:
dainslie
07/06/2023, 3:46 PM