directus-labs / directus-labs/directus-template-cli
🐛 New settings fail to override existing settings when loading template
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 191
- Forks
- 37
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in load-settings.ts and inspect mergeJsonStrings and loadSettings, focusing on the order of current database settings and incoming template settings passed to customDefu. Reproduce the issue by loading the simple-cms template into an empty Directus project. Done means project_name and project_color from the template override conflicting existing values while mergeArrays remains additive and duplicate-free.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100