<@ULVA73B9P> Hi! I want to use from prefect.utilit...
# ask-marvin
a
@Marvin Hi! I want to use from prefect.utilities.annotations.quote to speed up tasks that depend on large task outputs. How can I use this pattern together with task.submit() ? See example code below:
Copy code
from prefect import task, flow
from prefect.utilities.annotations import quote

@task
def big_output():
    return [1 for _ in range(10**7)]

@task
def big_input(x):
    print(len(x))

@flow
def slow_flow():
    x = big_output.submit()
    big_input.submit(quote(x))

if __name__ == "__main__":
    slow_flow()
I'm trying to get the big_input task to start quickly after big_output task, but I get this error:
TypeError: object of type 'PrefectFuture' has no len()
m
It seems that while searching for relevant documents, we did not find exactly what we were looking for in relation to speeding up dependent tasks in Prefect with large outputs or using
quote
with
task.submit()
. However, searching the GitHub issues for the error you mentioned did not yield any directly related issues in the PrefectHQ repository. To address your usage question with
quote
and
task.submit()
, here's what you need to know: The
quote
function from Prefect's
utilities.annotations
module is used to avoid early evaluation of task outputs, which allows you to compose task dependencies that pass outputs between tasks without serializing and copying large data immediately. To fix the
TypeError
you're facing,
big_input.submit()
needs to properly unwrap the quoted future. When you pass
quote(x)
to
big_input
, you're passing a
PrefectFuture
object, and you cannot take the length of that future directly, as it is not the actual result of the task. One potential solution is to have
big_input
wait for the actual value of
x
inside the task. This can be done using the
get
method on the future object. Here's a simple modification to your
big_input
function:
Copy code
python
@task
def big_input(x):
    real_value = x.get()  # Unwrap the actual value from the future.
    print(len(real_value))
And your
slow_flow
function should remain unchanged:
Copy code
python
@flow
def slow_flow():
    x = big_output.submit()
    big_input.submit(quote(x))
This should allow your code to execute without the
TypeError
, as the
get()
method on the quoted Prefect future is used to obtain the real value once it's available. If you still encounter issues, you might need deeper insight into Prefect's execution model and the specific use of
quote
with
task.submit()
. You could consider reaching out on Prefect's community Slack or support channels for more direct assistance.