Fix project config ordering for partial loaded elementSources entries#18719
Open
wvell wants to merge 1 commit intocraftcms:5.xfrom
Open
Fix project config ordering for partial loaded elementSources entries#18719wvell wants to merge 1 commit intocraftcms:5.xfrom
wvell wants to merge 1 commit intocraftcms:5.xfrom
Conversation
Applying project config to a clean install only sorted keys by depth.
This allowed `sections` changes to run before related
`elementSources` entries were fully built. Resulting in the error:
In ElementSources.php line 147:
Undefined array key "type"
Sort pending changes by top-level key first, then by depth within each
group. This makes sure only complete elements are applied.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When project config is applied to a clean install, pending changes are currently
sorted only by path depth. That can cause
sectionschanges to be processedbefore related
elementSourcesentries are fully constructed.In our case,
handleChangedSection()ends up reading element sources while anelementSourcesentry only contains nested values likedefaultSortandtableAttributes, but is still missing scalar keys such astype. That leadsto:
in
ElementSources::defineSources().elementSources...defaultSortelementSources...defaultSortelementSources...tableAttributeselementSources...tableAttributessections...siteSettingselementSources...0elementSources...0sections...siteSettingssections...entryTypessections...entryTypesBefore this change,
sections...siteSettingscould run before the parentelementSources...0entry had been fully applied. After this change, allelementSourcespaths are processed first, so section change handlers neverobserve partially-built element source configs.
This change sorts pending changes by top-level config key first, and then by
depth within each group.
A minimal regression test has been added to reproduce that failure mode.
Related issues
#18720