-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[pythonic resources][rfc] Adjust EnvVar behavior to explicitly disallow direct usage #14490
Conversation
Current dependencies on/for this PR:
This comment was auto-generated by Graphite. |
This one seems better to me. We could also offer a method to access the underlying value so that users won't have to import |
1b9048d
to
1ee1c12
Compare
Deploy preview for dagit-storybook ready! ✅ Preview Built with commit cb4aa7c. |
Deploy preview for dagit-core-storybook ready! ✅ Preview Built with commit cb4aa7c. |
Deploy preview for dagster-university ready! ✅ Preview Built with commit 1ee1c12. |
f'Attempted to directly retrieve environment variable IntEnvVar("{self.name}").' | ||
" IntEnvVar should only be used as input to Dagster config or resources." |
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.
Add:
"If you want to access the environment variable directly, you can call get_value
on this object, or os.getenv
directly"
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.
We could also save.
"The purpose of EnvVar
is to defer retrieval to right before the step is executed, and to be viewable in the UI"
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.
Let's do a turn on the error messaging, which is the most important part of this PR.
f'Attempted to directly retrieve environment variable EnvVar("{self.env_var_name}").' | ||
" EnvVar should only be used as input to Dagster config or resources." | ||
) |
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.
Same here.
f'Attempted to directly retrieve environment variable IntEnvVar("{self.name}").' | ||
" IntEnvVar should only be used as input to Dagster config or resources." |
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.
We could also save.
"The purpose of EnvVar
is to defer retrieval to right before the step is executed, and to be viewable in the UI"
Updated copy 👍 |
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.
Great. Consider a common function to share between two callsites to generate error string.
""" | ||
raise RuntimeError( | ||
f'Attempted to directly retrieve environment variable EnvVar("{self.env_var_name}").' | ||
" EnvVar defers resolution of the env var value until run time, and should only be" |
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.
spell out "environment variable" instead of "env var"
ff9101c
to
cb4aa7c
Compare
Deploy preview for dagster-docs ready! Preview available at https://dagster-docs-bh67a7ww3-elementl.vercel.app Direct link to changed pages: |
Summary
Alternative RFC to #14488. Keeps
EnvVar
as a direct subclass ofstr
but errors on resolving the value via__str__
to explicitly prevent users from usingEnvVar
outside of resource/config contexts. Right now we're sort of in the worst of both worlds where a user can use anEnvVar
in inapproporiate places and they get an odd result.EnvVar
value as a string will hit an error:EnvVar
name or value:Test Plan
Set of unit tests, existing unit tests.