-
Notifications
You must be signed in to change notification settings - Fork 8
feature: constrain value of ENVIRONMENT setting #244
Comments
We are starting to amass a bit of functionality that is condition upon the environment setting. E.g., sentry init disabled by default in test and local environments, alternate logging config if environment is local, and server reloading automatically configured for local environment. So allowing this setting to be _anything_ doesn't make a lot of sense. Closes #244
I use an Enum internally with these values as well, but can they be adapted to all projects? |
To clarify, are you asking if all projects can fit into the dev/stage/prod/local/test paradigm? What values do you use in your enum? If a downstream app has requirements beyond those they can always create their own local settings object with a variable specific to thier needs. And we can always consider adding more environments if they are common enough. Another way to look at it is that we are doing the wrong thing by overloading the |
I'd like to make a release soon, so LMK if you think this should be left out. I'm happy to hold off as it's not a critical issue. |
Specifically, I wonder if one need some more values, how can a local enum be used without avoiding lib's app.ENVIRONMENT to fail because it's an unknown value from the lib's env enum? |
Another approach could be: # settings.py
class AppSettings(BaseSettings):
ENVIRONMENT: str = "prod"
TEST_ENVIRONMENT: str = "test"
LOCAL_ENVIRONMENT: str = "local"
app = AppSettings()
IN_TEST_ENVIRONMENT = app.ENVIRONMENT == app.TEST_ENVIRONMENT
IN_LOCAL_ENVIRONMENT = app.ENVIRONMENT == app.LOCAL_ENVIRONMENT something like that? |
Actually I think It's part of a bigger issue which is: How can we easily override any setting in downstream projects? settings.server.RELOAD = settings.app.ENVIRONMENT == ApiEnv.LOCAL.value But this wouldn't work as my |
But maybe It's not something we want to support as the lib is already a bit opiniated design wise, so enforcing env default values is ok. |
That looks good! I find it a bit cleaner to write |
isn't this just the same as:
Yes, this. Configuration by environment is pretty fundamental to the pattern here.
OK cool, I'll back out that other commit and go with this. I think it adds enough structure:) |
I still have to set |
Interesting! I've always gone the other way - in my production apps I don't have any "default" environment to force explicitly setting all values. I backed off from that stance with this library as I figured it wouldn't be a very popular design choice. In practice, it just means that the default environment values are set in terraform config instead of the application, but that means that they can all be easily modified without having to modify the application source. |
Just a matter of preference I guess ;) |
We are starting to amass a bit of functionality that is condition upon the environment setting. E.g., sentry init disabled by default in test and local environments, alternate logging config if environment is local, and server reloading automatically configured for local environment. So, it makes sense to have a bit more structure around these checks. Closes #244
We are starting to amass a bit of functionality that is condition upon the environment setting. E.g., sentry init disabled by default in test and local environments, alternate logging config if environment is local, and server reloading automatically configured for local environment. So, it makes sense to have a bit more structure around these checks. Closes #244
We have a bit of logic that depends on the value of
settings.AppSettings.ENVIRONMENT
variable, so we probably need to make the allowed values for that more structured, at the moment it is just typedstr
.I'm thinking allowed values should be "dev", "stage", "prod", "local", "test", and we can either use
Literal
orEnum
for this.The text was updated successfully, but these errors were encountered: