Shane Keller
02/24/2024, 10:04 PMScout
02/24/2024, 10:04 PMEnvVar
within Dagster's configuration system. The EnvVar
is used to specify that a configuration value should be sourced from an environment variable at runtime, and it does not provide a parameter for a default value.
However, there has been discussion in the Dagster community about adding the ability to set a default value for EnvVar
. A feature request was opened on the Dagster GitHub repository to allow setting a default value for EnvVar
, so that it would not raise an error if the environment variable is not defined when evaluated. The issue is still open, indicating that the feature has not yet been implemented in the official Dagster release.
For the time being, if you need to provide a default value for an environment variable in your Dagster code, you might consider using Python's os.getenv
method, which allows you to specify a default value if the environment variable is not found. Here's an example from the documentation:
python
import os
# Accessing an environment variable with a default value
print(os.environ.get('HOME', '/home/default'))
In this example, if the HOME
environment variable does not exist, the string /home/default
will be returned instead.
If you're working within Dagster's configuration system and need to handle optional environment variables, you may need to implement a custom solution or use a workaround until such a feature is officially supported. Allow to set default value for EnvVar
button Make EnvVar functional even outside Dags... button Set default value for StringSource confi... button Environment Variables in Python | Dagste... button Thank you for your feedback!