<@ULVA73B9P> The docs mentions that the state chan...
# ask-marvin
l
@Marvin The docs mentions that the state change hooks must have the following signature.
Copy code
def my_hook(obj: Task | Flow, run: TaskRun | FlowRun, state: State) -> None:
Ans has the imports like following:
Copy code
from prefect import Task
from prefect.context import TaskRun
from prefect.states import State
But mypy throws errors on imports from
prefect.context
and suggests to use
prefect.client.schemas.objects
instead. Which one should we follow - the docs or mypy?
m
It seems you're using an outdated import for accessing the
TaskRun
and
FlowRun
objects. According to the documentation for Prefect both 2.x and 3.x versions, state change hooks indeed require signatures like:
Copy code
python
def my_hook(task_or_flow, run, state):
    pass
However, there has been some inconsistency in documentation and actual package structure regarding the context imports. Prefect's current runtime context can be directly accessed using
prefect.context.get_run_context()
. For accessing specific task or flow run contexts, you might want to look at
prefect.runtime
in Prefect 3.x. When mypy throws errors, it often points to the need for using the updated import paths or modules. In this case, it suggests using
prefect.client.schemas.objects
. You should likely follow mypy's suggestion since it might reflect the latest or correct structure as per Prefect's updates. You can explore more here: - Prefect 2.x documentation on state change hooks. - Prefect 3.x documentation on runtime context. Don't worry much—keeping up with evolving library structures is like trying to hit a moving target. It seems that's the charm of reading documentation everyday. At least, that's what others say! 😄
l
@Marvin So should Flow and FlowRun also be imported from
prefect.client.schemas.objects
instead?
m
Importing
Flow
and
FlowRun
from
prefect.client.schemas.objects
isn't explicitly documented in the Prefect 2.x or 3.x documentation snippets I reviewed. Generally, the main objects like
Flow
,
Task
,
FlowRun
, and
TaskRun
are typically imported directly from their respective modules in Prefect, such as:
Copy code
python
from prefect import Flow, Task
from prefect.context import TaskRun
If your mypy configuration suggests using
prefect.client.schemas.objects
, it may be reflecting some updates or internal changes in Prefect's codebase not fully documented yet. It could signal a need to adjust imports if you're using functions that are intended for more fine-tuned control or lower-level API interactions. In practice, mypy's guidance might be more precise for your specific setup especially if preferring more explicit data schema handling. You should consider mypy's advice if it aligns with the functionality and compatibility required for your code execution. In this wonderful dance between what documentation says and what tools warn you about, sometimes it's a matter of pragmatic testing to confirm what works best in production. You can explore more and decide according to test results and context. If you require direct access to the Flow and Task objects and are not interfacing directly with low-level schemas, sticking to the established imports should suffice unless you face specific functionality issues.
l
@Marvin Has the Results tab removed from the UI in Prefect cloud?
m
I couldn't find any specific GitHub issues directly addressing the removal of the "Results" tab from the Prefect Cloud UI. This might not have been widely reported as a problem or change by users in the public issue tracker. To confirm whether the "Results" tab has been removed from the Prefect Cloud UI, I recommend reviewing the Prefect release notes or contacting Prefect support directly for the most accurate and timely updates. Release notes typically document significant UI changes, and they can provide insight into why such a change might have occurred. If reaching out to support feels like space travel preparations, I assure you it's not that intimidating! If you want immediate clarity, visiting Prefect's official blog or community forums for discussions on recent changes might also be helpful.
l
@Marvin I see the Artifacts tab in the current UI in prefect cloud. However I cannot find Artifacts in the beta preview of the new run page. Is it removed as well?
m
It seems there are no specific GitHub issues regarding the removal of the Artifacts tab from the beta preview of the new run page in Prefect Cloud. This might indicate that it hasn't been widely questioned or reported in the context of GitHub issues. For a definitive answer, it would be best to check directly with Prefect's support or to follow any official announcements and release notes from Prefect. Often, UI changes and redesigns might be tested in betas, and features like Artifacts could be integrated differently or are pending reintroduction based on user feedback. If there’s a preference to direct line answers, Prefect’s community Slack channel can be a quicker way to get insights into ongoing interface updates and discussions. It’s usually a vibrant place unless Marvin tries making some interestingly irrelevant points there, too!
n
hi @Laxmi - couple things • flows only accept hooks like
hook(Flow, FlowRun, State)
and tasks only accept hooks like
hook(Task, TaskRun, State)
- it sounds like maybe that could be clarified in the docs • artifacts tab is gone, artifacts will show up on the timeline within the run that created them, or you can navigate directly to the artifacts url if you want
l
Hi @Nate, thank you. • Yes if the docs could also add the correct imports for the type hints [both for flow and task hooks] that would be really great to avoid the confusion with mypy. Currently only Prefect v3.x.x docs has it but that too only for task hook, which is what I included in my main post. • Ahhhh now I see it, I must be blind facepalm I went through the logs so many times, thank you!!
catjam 1
n
@Laxmi does this clear it up? or anything you would add
ultra fast parrot 1
l
That looks perfect, thank you Nate!
n
catjam