https://prefect.io logo
Title
k

Kyle Austin

03/16/2023, 5:31 PM
I have noticed that tasks work on copies of the inputs and not directly with the inputs itself. For example the following flow would run forever.
from prefect import task, flow, get_run_logger
from logging import Logger
@task()
def pop_element_zero(ls: list, logger: Logger) -> list:
    val = ls.pop(0)
    <http://logger.info|logger.info>(f'Just popped {val} from the list {ls}')
    return val

@flow()
def pop_task_flow():
    logger = get_run_logger()
    ls = [1,2,3]
    while ls:
        pop_element_zero(ls=ls, logger=logger)

if __name__ == "__main__":
    pop_task_flow()
It makes sense (really good for making tasks retry-proof when the inputs are immutable objects). But I have some flows where I would like to not have this behavior. Is there a task decorator param that I am missing that would allow the user to let the task work directly on its inputs and not copies?
z

Zanie

03/16/2023, 5:34 PM
If you use the
prefect.utilities.annotations.quote
utility we should not create a copy
i.e.
pop_element_zero(ls=quote(ls))
k

Kyle Austin

03/16/2023, 5:40 PM
Oh cool! Thanks so much for the super quick reply @Zanie! Really appreciate you guys taking these slack posts so seriously. You all make slack such a great prefect resource!
2
z

Zanie

03/16/2023, 5:41 PM
You’re welcome 🙂
lmk if it doesn’t work!
k

Kyle Austin

03/16/2023, 5:42 PM
Worked like a charm! I love it!