I have noticed that tasks work on copies of the in...
# ask-community
k
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.
Copy code
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
If you use the
prefect.utilities.annotations.quote
utility we should not create a copy
i.e.
pop_element_zero(ls=quote(ls))
k
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
You’re welcome 🙂
lmk if it doesn’t work!
k
Worked like a charm! I love it!