dynaconf icon indicating copy to clipboard operation
dynaconf copied to clipboard

dynaconf list tells I am in "development" mode, when choosing no environement.

Open antoine-gallix opened this issue 2 years ago • 3 comments

Describe the bug

when working with environments, the command dynaconf -i path.to.settings list displays by default working in development environment. It's confusing because it seems more logical to call it default environement. For example I have default values, and two environements called dev and prod. When I choose them, I get respectively working in dev environment and working in prod environment. If I don't select any of them, the message tells me I'm in development environement, that confuses everyone in the team. I guess it's worse if you actually name one of your environement development.

To Reproduce

start in a fresh dir, dynaconf init, and add environements=True in the config.py loader.

then dynaconf -i path.to.settings list

it displays working in development environment

  1. Having the following folder structure
├── __pycache__
│   └── config.cpython-310.pyc
├── config.py
└── settings.toml
  1. Having the following config files: default

  2. Having the following app code:

no app

  1. Executing under the following environment fresh env with just dynaconf

Expected behavior

see bug description

Environment (please complete the following information):

  • OS: ubuntu 22.04
  • Dynaconf Version 3.1.9

antoine-gallix avatar Aug 03 '22 16:08 antoine-gallix

That is by design, dynaconf selects development as the default when no env is set.

I agree that it can be confusing, so I am marking this to be resolved in 4.0.0, it can be a breaking change for those already relying on the current behavior.

I think in 4.0.0 we can call it default or main or even have a better message saying:

When environments=False (default)

$ dynaconf ... list
Dynaconf default environment
var<type>: value

When environments=True (assumes default, development, production)

$ dynaconf ... list
Dynaconf default environment
var<type>: value

When environments=["abc", "def", "ghi"] (first on the list is the default)

$ dynaconf ... list
Dynaconf abc environment
var<type>: value

rochacbruno avatar Aug 04 '22 08:08 rochacbruno

yes you're right, it was not really a bug at the end. thanks for the quick reaction Bruno.

antoine-gallix avatar Aug 04 '22 13:08 antoine-gallix

This is especially annoying if you want to have a local environment called "local" and don't want those checking out your code have a complicated startup preflight. It seems odd to me that a configuration library doesn't allow configuration of default values!

You can override env using your own "implementation" of the env switcher

from dynaconf import Dynaconf, Validator
from os import getenv

envvar_prefix = "MY_PREFIX"
env_switcher = f"{envvar_prefix}_ENVIRONMENT"
default_env = "local"

settings = Dynaconf(
    envvar_prefix=envvar_prefix,
    env=getenv(env_switcher, default_env),
    ... #other settings
)

EdwardBlair avatar Apr 11 '23 15:04 EdwardBlair