Skip to content

🐛 New settings fail to override existing settings when loading template #78

@joggienl

Description

@joggienl

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions