Will the values in settings.py merge with the defauts?

I add additional settings in settings.py when I test token and keycloak as described Keycloak β€” Pulp Project 3.48.0 documentation.
What I did:

  • run a container basic, get the defaults conf about
    INSTALLED_APPS AUTHENTICATION_BACKENDS TEMPLATES , by dyconf list , then
  • add these additional lines

For exemple: the part about INSTALLED_APPS becomes:

INSTALLED_APPS = [
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.postgres',
    'import_export',
    'django_filters',
    'django_guid',
    'drf_spectacular',
    'rest_framework',
    'pulpcore.app',
    'pulp_ansible.app.PulpAnsiblePluginAppConfig',
    'pulp_certguard.app.PulpCertGuardPluginAppConfig',
    'pulp_container.app.PulpContainerPluginAppConfig',
    'pulp_deb.app.PulpDebPluginAppConfig',
    'pulp_gem.app.PulpGemPluginAppConfig',
    'pulp_maven.app.PulpMavenPluginAppConfig',
    'pulp_ostree.app.PulpOstreePluginAppConfig',
    'pulp_python.app.PulpPythonPluginAppConfig',
    'pulp_rpm.app.PulpRpmPluginAppConfig',
    'pulp_file.app.PulpFilePluginAppConfig',
    'storages',
    'django_readonly_field',
    'social_django',
    'rest_framework.authtoken'
    ]

My question is: if I just add

INSTALLED_APPS = [
    'social_django',
]

in my settings , will it be deep merger with the default settings? or I have to put the complete list
in my settings.py?

Hello @xm1234567 ,
You example will replace all INSTALLED_APP, but you can use this to enable merging:

INSTALLED_APPS = [
    'social_django',
    'dynaconf_merge',
]

Using that merge token, Dynaconf will append social_django to the end of the list.
You can check other merging strategies here, if you need to.

Let me know if that helps!

3 Likes

@pedro-psb sorry for late reply, thank you for answering my question :slight_smile:

Great! the list can be merged with dynaconf_merge easily!

the doc says The dynaconf_merge and @merge functionalities work only for the first level keys, it will not merge subdicts or nested lists (yet). ref here . So to add the additional setting as belows, i have to put all settings, since context_processors is not the first level keys. just to want to confirm this one :slight_smile:

TEMPLATES = [
    {
        ...
        'OPTIONS': {
            ...
            'context_processors': [
                ...
                'social_django.context_processors.backends',
                'social_django.context_processors.login_redirect',
                ...
            ]
        }
    }
]
1 Like

So to add the additional setting as belows, i have to put all settings, since context_processors is not the first level keys. just to want to confirm this one :slight_smile:

Yes, currently you have to copy the content.

You actually can merge nested dicts with the dunder separator method. For list we have the limitation that we don’t support index access with this syntax.

There is a PR that should be merged in 3.3.0 that will probably add support for doing this:

# note the 0 for accessing the TEMPLATES first item.
TEMPLATES__0__OPTIONS__context_processor = [
    'social_django.context_processors.backends',
    'social_django.context_processors.backends',
    'dynaconf_merge',
]
1 Like

just to add my example of Dunder merging for memory.
The part needed to merge is under DEFAULT_AUTHENTICATION_CLASSES , the new authentication way rest_framework.authentication.TokenAuthentication:

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework.authentication.TokenAuthentication',  # <-- the part to add for token creation
    ],
}

I did like this with dunder merge:

#For token creation
REST_FRAMEWORK__DEFAULT_AUTHENTICATION_CLASSES = ['rest_framework.authentication.TokenAuthentication','dynaconf_merge']

Note the __ for dunder merging.

1 Like