craftcms / craftcms/cms

[5.x]: Applying the project config can change the meta names table

Open
#16,593 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
3.6k
Forks
705
Avg merge
1d 5h
Merged PRs (30d)
134

Description

What happened?
Description

Just got another case where running project-config/apply or up will unexpectedly change the project config. It will always bring the list of names in the project.yaml unter meta -> __names__ in order if its not sorted correctly.

Steps to reproduce
  1. Switch the order of any two lines in the __names__ map in config/project/project.yaml
  2. Run craft up
  3. The previous change is reverted.

Of course, you don't do this manually during normal operations. But it can frequently happen when resolving merge conflicts while merging or rebasing a git branch.

Expected behavior

Running project-config/apply should never change the config/ folder. It should either leave the issue intact, to be fixed the next time a modification is made. Or throw an error with an error message that tells the user how to fix the problem.

Silently fixing the issue might seem preferable at first glance. But it's a problem when applying the config can at any point change the config. It's a problem when you're reviewing a PR and suddenly have changed files in your config folder. It's also a problem when you deploy to production, when changed files might result in the next deployment failing.

Some anecdotal evidence for this: You can see the same issue in earlier versions of npm. npm install would suddenly change the package-lock.json, which is a problem if you have a CI/CD pipeline. To fix this, npm ci was introduced, which will reliably only ever install dependencies, but never change the state of the lock file. Later on, the behaviour of the install command was modified, because they realized that installing and updating should be completely separate actions.

Another option might be to introduce another command like project-config/ci, which will do the same thing as apply, but never modify the config, and throw an error if any issues are detected. This would allow people to opt into this more strict behaviour, without modifying the existing behaviour.

Also see my comment here on this same issue: https://github.com/craftcms/cms/issues/16086#issuecomment-2621921042

Actual behavior

project-config/apply will unexpectedly change the config.

Craft CMS version

5.6.0.2

PHP version

8.3

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue by reordering entries in config/project/project.yaml under meta.names, then run craft up or project-config/apply and inspect the project-config command path. Determine how the command handles this ordering change. Done means applying the config leaves the config/ folder untouched, or reports an actionable error instead of silently rewriting it.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
cli, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.