Skip to content

[5.x]: Invalid section ID when applying the project config #15787

@MoritzLost

Description

@MoritzLost

What happened?

Description

I'm getting an error when applying the project config in a particular branch. I can't reliably reproduce the error yet, but it's happened multiple times in this specific branch.

I have a branch that adds some sections, entry types and fields. Last time I worked on it, I created some entries to test with. Then I went back to another branch and applied the config, so all those sections, entry types and test entries were (soft-)deleted. Now when I go back to the to branch and run php craft up, I quickly get this error:

❯ php craft up
Checking for pending Craft and plugin migrations ...
No new migrations found. Your system is up to date.

Applying changes from your project config files ...
- updating dateModified ... done
- adding entryTypes.45b0f636-480b-4bc2-b8f0-0beb66debd75.fieldLayouts.ffba8421-71c0-4967-a483-ec914c319518.tabs.0.elements.4.elementCondition.conditionRules.0 ... 
  - adding meta.__names__.45b0f636-480b-4bc2-b8f0-0beb66debd75 ... done
  - adding entryTypes.45b0f636-480b-4bc2-b8f0-0beb66debd75 ... 
    - adding meta.__names__.2117db37-8708-4ac7-a076-e3b27d1ac7c8 ... done
    - adding fields.2117db37-8708-4ac7-a076-e3b27d1ac7c8 ... done
    - adding meta.__names__.a493df13-b10f-45d8-a048-cd2e6cf91d83 ... done
    - adding fields.a493df13-b10f-45d8-a048-cd2e6cf91d83 ... done
error: Invalid section ID: 18

When I run php craft up again after this, the command says the system is up to date, but deletes all the new config entities from the config folder:

❯ git status
// …

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        deleted:    config/project/entryTypes/bulletin_board--45b0f636-480b-4bc2-b8f0-0beb66debd75.yaml
        deleted:    config/project/entryTypes/bulletin_board_post--29bd856c-c0e2-4b07-83aa-0c30dc6acd8e.yaml
        modified:   config/project/project.yaml
        deleted:    config/project/routes/aaea878b-29df-4b75-ad8c-1c48430a63b9.yaml
        deleted:    config/project/routes/dc9dbc5a-4b5e-4228-a69d-ba4b93790f1c.yaml
        deleted:    config/project/routes/f3ca972e-536c-4d13-a744-b01828e7e331.yaml
        deleted:    config/project/sections/bulletin_board--c1b6392f-ad9e-4f3e-aad3-e8c25b5f6724.yaml
        deleted:    config/project/sections/posts--e1809aab-fd36-4ede-9314-49732237fa5a.yaml
        deleted:    config/project/users/groups/member--4ea16709-ea56-4dd8-9008-ca3f98710a0f.yaml

Here's the stacktrace from the console log:

2024-09-24 16:21:13 [console.ERROR] [yii\base\InvalidConfigException] yii\base\InvalidConfigException: Invalid section ID: 18 in /path/to/project/vendor/craftcms/cms/src/elements/Entry.php:1337
Stack trace:
#0 /path/to/project/vendor/craftcms/cms/src/elements/Entry.php(920): craft\elements\Entry->getSection()
#1 /path/to/project/vendor/craftcms/cms/src/helpers/ElementHelper.php(315): craft\elements\Entry->getSupportedSites()
#2 /path/to/project/vendor/craftcms/cms/src/services/Elements.php(2581): craft\helpers\ElementHelper::supportedSitesForElement(Object(craft\elements\Entry))
#3 /path/to/project/vendor/craftcms/cms/src/services/Entries.php(1464): craft\services\Elements->restoreElements(Array)
#4 /path/to/project/vendor/craftcms/cms/src/base/ApplicationTrait.php(1829): craft\services\Entries->handleChangedEntryType(Object(craft\events\ConfigEvent))
#5 /path/to/project/vendor/craftcms/cms/src/services/ProjectConfig.php(1179): craft\console\Application->craft\base\{closure}(Object(craft\events\ConfigEvent))
#6 [internal function]: craft\services\ProjectConfig->handleChangeEvent(Object(craft\events\ConfigEvent))
#7 /path/to/project/vendor/yiisoft/yii2/base/Component.php(641): call_user_func(Array, Object(craft\events\ConfigEvent))
#8 /path/to/project/vendor/craftcms/cms/src/models/ProjectConfigData.php(82): yii\base\Component->trigger('addItem', Object(craft\events\ConfigEvent))
#9 /path/to/project/vendor/craftcms/cms/src/services/ProjectConfig.php(1169): craft\models\ProjectConfigData->commitChanges(NULL, Array, 'entryTypes.45b0...')
#10 [internal function]: craft\services\ProjectConfig->handleChangeEvent(Object(craft\events\ConfigEvent))
#11 /path/to/project/vendor/yiisoft/yii2/base/Component.php(641): call_user_func(Array, Object(craft\events\ConfigEvent))
#12 /path/to/project/vendor/craftcms/cms/src/models/ProjectConfigData.php(82): yii\base\Component->trigger('addItem', Object(craft\events\ConfigEvent))
#13 /path/to/project/vendor/craftcms/cms/src/services/ProjectConfig.php(1289): craft\models\ProjectConfigData->commitChanges(NULL, Array, 'entryTypes.45b0...', true, NULL, true)
#14 /path/to/project/vendor/craftcms/cms/src/services/ProjectConfig.php(1311): craft\services\ProjectConfig->craft\services\{closure}('entryTypes.45b0...', true)
#15 /path/to/project/vendor/craftcms/cms/src/services/ProjectConfig.php(627): craft\services\ProjectConfig->_applyChanges(Array, Object(craft\models\ProjectConfigData), Object(craft\models\ReadOnlyProjectConfigData))
#16 /path/to/project/vendor/craftcms/cms/src/console/controllers/ProjectConfigController.php(328): craft\services\ProjectConfig->applyExternalChanges()
#17 [internal function]: craft\console\controllers\ProjectConfigController->actionApply()
#18 /path/to/project/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#19 /path/to/project/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#20 /path/to/project/vendor/yiisoft/yii2/console/Controller.php(180): yii\base\Controller->runAction('apply', Array)
#21 /path/to/project/vendor/craftcms/cms/src/console/ControllerTrait.php(89): yii\console\Controller->runAction('apply', Array)
#22 /path/to/project/vendor/craftcms/cms/src/console/Controller.php(216): craft\console\Controller->traitRunAction('apply', Array)
#23 /path/to/project/vendor/yiisoft/yii2/base/Module.php(552): craft\console\Controller->runAction('apply', Array)
#24 /path/to/project/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('project-config/...', Array)
#25 /path/to/project/vendor/craftcms/cms/src/console/Application.php(91): yii\console\Application->runAction('project-config/...', Array)
#26 /path/to/project/vendor/yiisoft/yii2/base/Controller.php(212): craft\console\Application->runAction('project-config/...', Array)
#27 /path/to/project/vendor/craftcms/cms/src/console/Controller.php(207): yii\base\Controller->run('project-config/...', Array)
#28 /path/to/project/vendor/craftcms/cms/src/console/controllers/UpController.php(76): craft\console\Controller->run('project-config/...')
#29 [internal function]: craft\console\controllers\UpController->actionIndex()
#30 /path/to/project/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#31 /path/to/project/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#32 /path/to/project/vendor/yiisoft/yii2/console/Controller.php(180): yii\base\Controller->runAction('', Array)
#33 /path/to/project/vendor/craftcms/cms/src/console/ControllerTrait.php(89): yii\console\Controller->runAction('', Array)
#34 /path/to/project/vendor/craftcms/cms/src/console/Controller.php(216): craft\console\Controller->traitRunAction('', Array)
#35 /path/to/project/vendor/yiisoft/yii2/base/Module.php(552): craft\console\Controller->runAction('', Array)
#36 /path/to/project/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('up', Array)
#37 /path/to/project/vendor/craftcms/cms/src/console/Application.php(91): yii\console\Application->runAction('up', Array)
#38 /path/to/project/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('up', Array)
#39 /path/to/project/vendor/craftcms/cms/src/console/Application.php(122): yii\console\Application->handleRequest(Object(craft\console\Request))
#40 /path/to/project/vendor/yiisoft/yii2/base/Application.php(384): craft\console\Application->handleRequest(Object(craft\console\Request))
#41 /path/to/project/craft(12): yii\base\Application->run()
#42 {main} {"memory":36301344,"exception":"[object] (yii\\base\\InvalidConfigException(code: 0): Invalid section ID: 18 at /path/to/project/vendor/craftcms/cms/src/elements/Entry.php:1337)"} 

Looks like it's trying to restore the previously created entries, but fails because the section doesn't exist (yet)?

I tried running gc/run to delete all trashes and soft-deleted entries, after that I can switch branches and apply the config without getting this error. So most likely it's related to those soft-deleted entries?

Craft CMS version

5.4.4

PHP version

8.3

Operating system and version

OS X

Database type and version

MySQL 8

Image driver and version

No response

Installed plugins and versions

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions