Using Dynaconf's @get with a list produces an unexpected nested dict/map

20 hours ago 2
ARTICLE AD BOX

I have certain configuration values that I need to have visible in multiple places in my configuration tree. I am using Dynaconf 3.2.12, testing with both Python 3.8 and 3.11. I am unclear if this is a bug or some limitation of my understanding. The following is a minimal example that demonstrates the problem.

# dynaconf_example.py from dynaconf import Dynaconf settings = Dynaconf( settings_files=['dynaconf_example.toml'], environments=True, env_switcher='EXAMPLE_ENV', ) # dynaconf_example.toml [default] # this doesn't seem to matter # dynaconf_merge = true [nonprod] # this doesn't seem to matter # dynaconf_merge = true [prod] # this doesn't seem to matter # dynaconf_merge = true [default.google] domain = 'example.org' [nonprod.google] domain = 'nonprod.example.org' [prod.google] domain = 'prod.example.org' # this doesn't seem to matter #[default.google.calendar] #dynaconf_merge = true #calendar_ids = [] [nonprod.google.calendar] calendar_ids = ['a', 'b'] [prod.google.calendar] calendar_ids = ['c', 'd'] [default.carrot] google = '@get google' [default.celery.google] domain = '@get google.domain' [default.celery.google.calendar] calendar_ids = '@get google.calendar.calendar_ids' [default.onion.google] domain = '@get google.domain' calendar.calendar_ids = '@get google.calendar.calendar_ids'

Using the dynaconf get command shows what I want, for the carrot branch:

$ EXAMPLE_ENV=nonprod dynaconf -i dynaconf_example.settings get carrot|jq -C . { "google": { "calendar": { "calendar_ids": [ "a", "b" ] }, "domain": "nonprod.example.org" } }

And what I am getting instead, for the celery and onion branches:

$ EXAMPLE_ENV=nonprod dynaconf -i dynaconf_example.settings get celery|jq -C . { "google": { "calendar": { "calendar_ids": { "calendar_ids": [ "a", "b" ] } }, "domain": "nonprod.example.org" } } $ EXAMPLE_ENV=nonprod dynaconf -i dynaconf_example.settings get onion|jq -C . { "google": { "calendar": { "calendar_ids": { "calendar_ids": [ "a", "b" ] } }, "domain": "nonprod.example.org" } }

This is obviously a reduced example with a few faked names, so while the carrot branch works, there is a lot of other stuff at the google level that I don't want to copy. I have played around with setting dynaconf_merge at various places and with setting an empty list in the default env for the calendar_ids, to no avail.

(Possibly related: I have had similar issues with an intermediate dict/map/container being introduced with values loaded from a .py file, which was implemented to use importlib_resources ; I was able to work around these because the resulting value was a string, so I could get the value I needed using @format {this.x.y.z} . This doesn't work for lists; I just end up with a list in a string.)

Read Entire Article