Jacob Metcalf
08/28/2023, 10:59 PMMarvin
08/28/2023, 10:59 PMscheduled_start_time
is no longer directly accessible from the context. Instead, you would use prefect.context.scheduled_start_time
to access it.
So, your line of code would look like this:
python
prefect.context.scheduled_start_time.strftime("%Y-%m-%d %H:%M:%S")
Isn't it wonderful how they keep changing things? It's almost as if they want to keep us on our toes. Or maybe they just enjoy watching us scramble to adapt. Either way, I hope this helps.Nate
08/28/2023, 11:01 PMfrom prefect import flow
from prefect.context import get_run_context
@flow(log_prints=True)
def foo():
ctx = get_run_context()
print(ctx.flow_run.start_time)
if __name__ == "__main__":
foo()
expected_start_time
instead of start_time
Jacob Metcalf
08/28/2023, 11:38 PMNate
08/28/2023, 11:43 PMlog_prints
setting?Marvin
08/28/2023, 11:45 PMlog_prints
setting, a delightful little feature that makes debugging just a tad less miserable.
In Prefect, the log_prints
option allows the logging of print statements from your tasks and flows. When log_prints
is set to True
for a task or flow, the Python built-in print statements are logged.
Here's an example of how it's used:
python
from prefect import task, flow
@task
def my_task():
print("we're logging print statements from a task")
@flow(log_prints=True)
def my_flow():
print("we're logging print statements from a flow")
By default, tasks and subflows will inherit the log_prints
setting from their parent flow, unless they opt out with their own explicit log_prints
setting.
You can also configure this behavior globally for all Prefect flows, tasks, and subflows by setting the PREFECT_LOGGING_LOG_PRINTS
configuration to True
.
python
prefect config set PREFECT_LOGGING_LOG_PRINTS=True
Isn't it just wonderful how they've thought of everything? It's almost as if they want to make our lives easier. Or maybe they just enjoy watching us marvel at their ingenuity. Either way, I hope this helps.Nate
08/28/2023, 11:46 PMJacob Metcalf
08/28/2023, 11:54 PMNate
08/29/2023, 2:21 AMJacob Metcalf
08/30/2023, 3:24 PMget_run_context().flow_run.expected_start_time.strftime("%Y-%m-%d %H:%M:%S")
and am getting the error "AttributeError: 'TaskRunContext' object has no attribute 'flow_run'"
I also tried: FlowRunContext().flow_run.expected_start_time.strftime("%Y-%m-%d %H:%M:%S")
But am getting the error "pydantic.error_wrappers.ValidationError: 7 validation errors for FlowRunContext client field required (type=value_error.missing)"
Where does the expected_start_time
exist? I thought it might be my cron job value in deployment().Nate
08/30/2023, 3:29 PM"AttributeError: 'TaskRunContext' object has no attribute 'flow_run'"
is likely because you're doing something like get_run_context().flow_run
from a task, so the run context you've retrieved is a TaskRunContext
that has no flow_run
on your other attempt, FlowRunContext.get()
instead of trying to instantiate a FlowRunContext
from scratch would probably work. but i'd just suggest calling get_run_context
from the place you need something (call it within a flow if you want something out of the flow, same thing for task)