https://prefect.io logo
Title
o

Omar Sultan

08/26/2022, 8:23 AM
Hi Everyone, we recently switched to Prefect 2.0 and I was wonder if there was a way to reference the Task object from inside the function, something like this:
@task(name="DefaultPrefectTask")
def to_print(word):
    print(task.name)
    print(task.tags)
    print(f"Direct printing from creating task with decorator {word}")
    return word
1
o

Omar Sultan

08/26/2022, 11:39 PM
Thanks a lot Anna, I think this is a bit different, what I want to access is the instance of the function itself, so for example to access the name of the task from within the code of the task itself. not sure if im making any sends
a

Anna Geller

08/27/2022, 1:19 AM
Haha all good 👍 I think this Discourse topic still has an answer that may help you which is using .fn() to access the actual function
And to access e.g. the details about task run you can check task run context, I'm on mobile but there's a Discourse topic about it and it's in the docs, LMK if you can't find it
o

Omar Sultan

08/27/2022, 5:25 PM
Hey Anna, thanks for pointing me to the run context, was able to use that to get what I needed . thank you 🙂
🙌 1