This is a pathological case, but it seems possible...
# prefect-community
b
This is a pathological case, but it seems possible to end up with multiple tasks in the same flow having the same slug:
Copy code
import prefect as p

@p.task
def add_one(n):
    return n + 1

@p.task
def add_two(n):
    return n + 2

with p.Flow('f') as f:
    a = p.Parameter('a')
    b = add_one(a)
    b.slug = 'my_slug'
    c = add_two(a)
    c.slug = 'my_slug'

f.get_tasks(slug='my_slug') # returns both tasks

f.validate(). # passes
j
Hmmm, once a task is added to a flow we only check the set of slugs stored on the flow, not on the task itself. Modifying the slug of a task is frowned upon - perhaps we should disable that behavior.
Note that if you set the slug on the task before adding it to the flow, it will error appropriately.
Copy code
import prefect as p

@p.task
def add_one(n):
    return n + 1

@p.task
def add_two(n):
    return n + 2

with p.Flow('f') as f:
    a = p.Parameter('a')
    b = add_one(a, task_args={"slug": "my_slug"})
    c = add_two(a, task_args={"slug": "my_slug"})
You shouldn't need to set the
slug
for a task ever, since the slug is autogenerated for you. We've been thinking about deprecating and removing the
slug
kwarg/attribute on tasks completely, since they're never used once a task is added to a flow. I just opened an issue for this here: https://github.com/PrefectHQ/prefect/issues/2964
b
Sweet! That’ll do it 👍
i
When I was playing around with slugs for
targets
and
merge_parameters
@Chris White gave me these thoughts on slugs 2531
I wouldn't expect users to really interact with `slug`s honestly - the main purpose of a slug is to have a stable ID that allows the Prefect API to determine which Python object is undergoing state updates. Slugs are not an inherent property of tasks, they're a property of tasks within flows, hence the move away from storing them on task objects directly.
j
When we added the new
slug
behavior we discussed (but didn’t implement) adjusting the flow’s
validate()
method to check slugs. - https://github.com/PrefectHQ/prefect/pull/2531#issuecomment-626094592 Perhaps we should revisit just as a matter of hygiene;
validate()
is a useful method for ensuring graph integrity