Bugfix/upgrade to v5 and migrations that change sections #17262
Merged
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
Issue 1:
If you have a Single section with a Commerce Products or Commerce Variants relation field in its field layout, and you upgrade from v4 to v5.7+, you get the following error:
That’s because when the project config for a section changes, it triggers the
Entries::_ensureSingleEntry()
method, which attempts to save the element. In doing so, it triggers a query that gets the contents of the relation field to check whether it’s empty. However, by that time, the Commerce tables are still “old” (not upgraded to v5), causing the query to fail.Fix:
Mute the events before setting the
maxAuthors
for the section’s project config to 1. (The database value is already 1, as that was the default set during them221107_112121_add_max_authors_to_sections
migration.)Issue 2:
If you have a Solo edition with a Single section with a Commerce Products or Commerce Variants relation field in its field layout, and you upgrade from v4 to v5, you get the following error:
It’s the same cause as the previous issue - a single section is saved, triggering
_ensureSingleEntry
and a new Commerce Products query on the old Commerce tables.Fix:
Instead of using
Entries->saveSection()
, mute project config events, update project config, and update the section(s) in the database.Related issues
n/a reported via support
Thanks to @nfourtythree for debugging and proposing the solution.