https://prefect.io logo
p

Pedro Machado

12/02/2020, 1:29 AM
Hi. Bumping this message in case it got missed last night. Any feedback?
n

nicholas

12/02/2020, 1:38 AM
Hi @Pedro Machado - I'm thinking you could extend the
Parameter
class to introduce this custom logic (and validation!).
p

Pedro Machado

12/02/2020, 1:46 AM
That's what I was thinking. I'm curious as to whether this is a common pattern/need (generating dynamic parameter values when missing) or if there is a better way to accomplish what I am doing. Thanks, Nicholas!
n

nicholas

12/02/2020, 1:49 AM
I haven't personally seen it before but I find that extending base classes like that is almost always the most flexible and maintainable option... If you're passing around the parameter a lot anyway, I'm not sure there's a better solution except maybe to use context? https://docs.prefect.io/core/concepts/execution.html#context
p

Pedro Machado

12/02/2020, 1:50 AM
Is it an acceptable practice to modify the context at run time?
n

nicholas

12/02/2020, 1:54 AM
Ah no, you won't be able to modify that at runtime, you'd need pass it through the API (or the UI) or as env vars. Chris just let me know we already have a subclassed DateTimeParameter that would provide the validation you're looking for out of the box though! https://github.com/PrefectHQ/prefect/blob/master/src/prefect/core/parameter.py#L119
p

Pedro Machado

12/02/2020, 2:47 AM
The key piece for me is setting the default value based on some business logic. The validation is to make sure the date makes sense (not before x date or not after y date). I'll take a stab at subclassing
Parameter
Thanks for your help!
😄 1
2 Views