https://prefect.io logo
Title
b

Brett Naul

11/11/2019, 4:55 AM
bit of a philosophical q: why are `Parameter`s required to be unique rather than just all receiving the input? I mentioned to @Chris White that I need to duplicate a large part of one flow in multiple places, so I was toying with a pattern like
def add(x, y):
    return x + y

def add_to_x(y):
    x = Parameter('x')
    total = task(add)(x, y)

with Flow('flow') as f:
    add_to_x(1)
    add_to_x(2)
in this case you could just pass in
x
to the “factory” function instead, but in practice I have lots of parameters so it feels a bit clumsy. I’m sure there was a good reason for enforcing that parameters be unique; but doesn’t the fact that we’re able to assert that it’s unique mean that we could also just grab a reference to the already-existing task? 🤔
c

Chris White

11/11/2019, 3:50 PM
Hey @Brett Naul - so you’re expecting that every reference to
Parameter('x')
reference the same underlying parameter? I think there are two reasons we haven’t done this yet: - whenever a parameter is not required and provides a default value, we’d need to validate that every reference provides the same default - typically we try to encourage explicit code, and this has the opportunity to surprise people at run time That being said, I see the benefit in a scenario like this so I’m not against it necessarily
b

Brett Naul

11/11/2019, 4:23 PM
makes sense; right now to test it out I’m just doing
class GlobalParameter(Parameter):
    def __init__(self, name, slug=None, *args, **kwargs):
        super().__init__(name=name, *args, **kwargs)
        self.slug = slug or uuid.uuid4()
will let you know if anything goes 🤯
c

Chris White

11/11/2019, 4:25 PM
haha ok nice! Yea, I like your subclass approach because it’s explicit