directus-template-cli icon indicating copy to clipboard operation
directus-template-cli copied to clipboard

🐛 New settings fail to override existing settings when loading template

Open joggienl opened this issue 1 year ago • 1 comments

I discovered a bug in the load-settings.ts file where new settings from configuration files fail to properly override existing settings in the database. This occurs because the parameter order in the mergeJsonStrings function and loadSettings function incorrectly prioritizes existing values over new ones.

Current behavior

Currently in load-settings.ts:

function mergeJsonStrings(current: string, incoming: string): string {
  try {
    return JSON.stringify(customDefu(JSON.parse(current), JSON.parse(incoming)))
  } catch {
    return incoming // If not valid JSON, return the incoming value
  }
}

And in the main function:

const mergedSettings = customDefu(currentSettings, settings) as DirectusSettings

With the customDefu function, the second parameter should override the first. However, in these implementations, the current values (from the database) are being given precedence over the incoming values (from the new settings file).

Expected behavior

When loading settings, new configuration values from the settings file should override existing values in the database when there are conflicts.

Additional notes

The mergeArrays function doesn't seem to have this issue. It seems to be intentionally designed to be additive while avoiding duplicates.

Reproduction steps

If you would load an empty directus project, and apply the simple-cms template it would not update the project_name and project_color properly.

joggienl avatar Mar 25 '25 14:03 joggienl

This is intentional. When you apply a template to an existing project, your project's own settings (name, color, etc.) are kept, so applying doesn't rebrand it. New settings from the template still get added.

bryantgillespie avatar Nov 07 '26 14:11 bryantgillespie