Hi. Bumping this message in case it got missed las...
# ask-community
p
Hi. Bumping this message in case it got missed last night. Any feedback?
n
Hi @Pedro Machado - I'm thinking you could extend the
Parameter
class to introduce this custom logic (and validation!).
p
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
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
Is it an acceptable practice to modify the context at run time?
n
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
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