-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mock runtime via environment variable #9156
Conversation
✅ Deploy Preview for prefect-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is cool. Suggesting minor copyedits to the tip.
Co-authored-by: Bill Palombi <bill@prefect.io>
Just wondering, does |
@madkinsz it probably does, but requires users to use |
I've been using this feature for a while and it works like charm! However I discovered a problem with datetime variables: existing datetime context variables like |
@jcozar87 that seems reasonable; feel free to open a PR! |
Co-authored-by: Bill Palombi <bill@prefect.io>
Thank you for the feedback, I will do it! |
The PR PrefectHQ#9156 introduces a mechanism for mocking / manually setting runtime attributes via environment variable. In commit asmundo@a56c7a1 this functionality is extended to deployment and task_run runtime attributes. The environment variables substitute the real attribute values in case that environment variable names matches with the name of some flow_run, task_run or deployment attribute. However, if the type of the attribute is not str, that would lead to a type insconsistency (i.e. flow_run.scheduled_start_time is of type pendulum.DateTime, but environment variable PREFECT__RUNTIME__FLOW_RUN__SCHEDULED_START_TIME is of type str). Now cast environment variable types to its real attribute type if exists. The functionality has been extended to flow_run, task_run and deployments, however only flow_run.scheduled_start_time is of a type different than str. Code is ready to adapt for any of these types: bool, int, float, str and pendulum.DateTime. It would be easy to extend to more attribute types.
This PR introduces a mechanism for mocking / manually setting runtime attributes via environment variable. This was requested by a user looking to test their code and provide explicit known values for the attributes.
Example
To do this, a user only needs to set an appropriately prefixed environment variable, e.g.,
PREFECT__RUNTIME__TASK_RUN__NEW_KEY="foobar"
and nowprefect.runtime.task_run.new_key
evaluates to"foobar"
.Checklist
<link to issue>
"fix
,feature
,enhancement
,docs
.