craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.28k stars 635 forks source link

Migration Error applying m190913_152146_update_preview_targets #5610

Closed sarahschuetz closed 3 years ago

sarahschuetz commented 4 years ago

Description

I tried updating from Craft CMS 3.3.18.2 to 3.4.4.1 It doesn't matter if migrations are installed using the 'Finish' button or console -> same error

Stack Trace:

*** applying m190913_152146_update_preview_targets
Exception: Undefined offset: 6 (/Users/sarah/Projects/xx/xx/___dist/vendor/craftcms/cms/src/helpers/ElementHelper.php:265)
#0 /Users/sarah/Projects/xx/xx/___dist/vendor/craftcms/cms/src/helpers/ElementHelper.php(265): yii\base\ErrorHandler->handleError(8, 'Undefined offse...', '/Users/sarah/Pr...', 265, Array)
#1 /Users/sarah/Projects/xx/xx/___dist/vendor/craftcms/cms/src/services/Elements.php(1956): craft\helpers\ElementHelper::supportedSitesForElement(Object(craft\elements\Entry))
#2 /Users/sarah/Projects/xx/xx/___dist/vendor/craftcms/cms/src/services/Elements.php(530): craft\services\Elements->_saveElementInternal(Object(craft\elements\Entry), true, true, NULL)
#3 /Users/sarah/Projects/xx/xx/___dist/vendor/craftcms/cms/src/services/Sections.php(1545): craft\services\Elements->saveElement(Object(craft\elements\Entry))
#4 /Users/sarah/Projects/xx/xx/___dist/vendor/craftcms/cms/src/services/Sections.php(755): craft\services\Sections->_ensureSingleEntry(Object(craft\models\Section), Array)
#5 /Users/sarah/Projects/xx/xx/___dist/vendor/craftcms/cms/src/services/ProjectConfig.php(1084): craft\services\Sections->handleChangedSection(Object(craft\events\ConfigEvent))
#6 [internal function]: craft\services\ProjectConfig->handleChangeEvent(Object(craft\events\ConfigEvent))
#7 /Users/sarah/Projects/xx/xx/___dist/vendor/yiisoft/yii2/base/Component.php(627): call_user_func(Array, Object(craft\events\ConfigEvent))
#8 /Users/sarah/Projects/xx/xx/___dist/vendor/craftcms/cms/src/services/ProjectConfig.php(658): yii\base\Component->trigger('updateItem', Object(craft\events\ConfigEvent))
#9 /Users/sarah/Projects/xx/xx/___dist/vendor/craftcms/cms/src/services/ProjectConfig.php(1074): craft\services\ProjectConfig->processConfigChanges('sections.d6060d...')
#10 [internal function]: craft\services\ProjectConfig->handleChangeEvent(Object(craft\events\ConfigEvent))
#11 /Users/sarah/Projects/xx/xx/___dist/vendor/yiisoft/yii2/base/Component.php(627): call_user_func(Array, Object(craft\events\ConfigEvent))
#12 /Users/sarah/Projects/xx/xx/___dist/vendor/craftcms/cms/src/services/ProjectConfig.php(655): yii\base\Component->trigger('addItem', Object(craft\events\ConfigEvent))
#13 /Users/sarah/Projects/xx/xx/___dist/vendor/craftcms/cms/src/services/ProjectConfig.php(478): craft\services\ProjectConfig->processConfigChanges('sections.d6060d...', true, '')
#14 /Users/sarah/Projects/xx/xx/___dist/vendor/craftcms/cms/src/migrations/m190913_152146_update_preview_targets.php(54): craft\services\ProjectConfig->set('sections.d6060d...', Array)
#15 /Users/sarah/Projects/xx/xx/___dist/vendor/craftcms/cms/src/db/Migration.php(52): craft\migrations\m190913_152146_update_preview_targets->safeUp()
#16 /Users/sarah/Projects/xx/xx/___dist/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(725): craft\db\Migration->up()
#17 /Users/sarah/Projects/xx/xx/___dist/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(200): yii\console\controllers\BaseMigrateController->migrateUp('m190913_152146_...')
#18 /Users/sarah/Projects/xx/xx/___dist/vendor/craftcms/cms/src/console/controllers/MigrateController.php(314): yii\console\controllers\BaseMigrateController->actionUp(0)
#19 [internal function]: craft\console\controllers\MigrateController->actionUp(0)
#20 /Users/sarah/Projects/xx/xx/___dist/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#21 /Users/sarah/Projects/xx/xx/___dist/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#22 /Users/sarah/Projects/xx/xx/___dist/vendor/yiisoft/yii2/console/Controller.php(164): yii\base\Controller->runAction('up', Array)
#23 /Users/sarah/Projects/xx/xx/___dist/vendor/yiisoft/yii2/base/Module.php(528): yii\console\Controller->runAction('up', Array)
#24 /Users/sarah/Projects/xx/xx/___dist/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('migrate/up', Array)
#25 /Users/sarah/Projects/xx/xx/___dist/vendor/craftcms/cms/src/console/Application.php(87): yii\console\Application->runAction('migrate/up', Array)
#26 /Users/sarah/Projects/xx/xx/___dist/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('migrate/up', Array)
#27 /Users/sarah/Projects/xx/xx/___dist/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(craft\console\Request))
#28 /Users/sarah/Projects/xx/xx/___dist/craft(22): yii\base\Application->run()
#29 {main}
*** failed to apply m190913_152146_update_preview_targets (time: 2.249s)

Additional Info

I tried the update already a couple of days ago and it worked fine. I just reverted because of troubles with the spoon plugin. Now that that's fixed, I finally want to update. In the meanwhile one of the multisites was deleted (soft-delete). Might that be an issue?

sarahschuetz commented 4 years ago

UPDATE: manually removing 'dateDeleted' from the deleted site in the 'sites' table fixes the error, so the problem is definitely the deleted site. Removing 'dateDeleted' - updating - adding 'dateDeleted' is a good enough workaround at the moment for me. But it might still be interesting to you. :)

brandonkelly commented 4 years ago

Huh, weird, when you delete a site, any section settings associated with that site should get automatically deleted as well. Just tested locally and didn’t have any trouble updating a Craft 3.3 install, with a soft-deleted site, and a Single section that was once enabled for that site.

Do you still have a database backup from before the 3.4 update? If so, can you please send it along with your composer.json and composer.lock files, over to support@craftcms.com?

martinhellwagner commented 3 years ago

@brandonkelly

Hi Brandon – Martin here, a colleague of Sarah. We're getting an error with the same migration again, although it seems to be related to a different problem. This time, we tried to go from Craft 3.3.3 to Craft 3.6.10 (latest as of today). All the Composer packages are on their latest versions as well.

Stack Trace:

*** applying m190913_152146_update_preview_targets
Exception: Setting unknown property: nystudio107\seomatic\models\MetaSiteVars::referrer (/Users/martin/Documents/xx/___dist/vendor/yiisoft/yii2/base/Component.php:210)
#0 /Users/martin/Documents/xx/___dist/vendor/yiisoft/yii2/BaseYii.php(558): yii\base\Component->__set('referrer', 'no-referrer-whe...')
#1 /Users/martin/Documents/xx/___dist/vendor/yiisoft/yii2/base/BaseObject.php(107): yii\BaseYii::configure(Object(nystudio107\seomatic\models\MetaSiteVars), Array)
#2 /Users/martin/Documents/xx/___dist/vendor/nystudio107/craft-seomatic/src/models/MetaSiteVars.php(43): yii\base\BaseObject->__construct(Array)
#3 /Users/martin/Documents/xx/___dist/vendor/nystudio107/craft-seomatic/src/models/MetaBundle.php(174): nystudio107\seomatic\models\MetaSiteVars::create(Array)
#4 /Users/martin/Documents/xx/vendor/nystudio107/craft-seomatic/src/models/MetaBundle.php(144): nystudio107\seomatic\models\MetaBundle->normalizeMetaBundleData(true)
#5 /Users/martin/Documents/xx/___dist/vendor/nystudio107/craft-seomatic/src/services/MetaBundles.php(227): nystudio107\seomatic\models\MetaBundle::create(Array)
#6 /Users/martin/Documents/xx/___dist/vendor/nystudio107/craft-seomatic/src/fields/SeoSettings.php(251): nystudio107\seomatic\services\MetaBundles->getMetaBundleBySourceId('section', 3, 1)
#7 /Users/martin/Documents/xx/___dist/vendor/craftcms/cms/src/base/Element.php(1879): nystudio107\seomatic\fields\SeoSettings->serializeValue(Object(nystudio107\seomatic\models\MetaBundle), Object(craft\elements\Entry))
#8 /Users/martin/Documents/xx/___dist/vendor/yiisoft/yii2/validators/InlineValidator.php(84): craft\base\Element->validateCustomFieldContentSize('pluginSeomaticN...', NULL, Object(yii\validators\InlineValidator), Object(nystudio107\seomatic\models\MetaBundle))
#9 /Users/martin/Documents/xx/___dist/vendor/yiisoft/yii2/validators/Validator.php(261): yii\validators\InlineValidator->validateAttribute(Object(craft\elements\Entry), 'pluginSeomaticN...')
#10 /Users/martin/Documents/xx/___dist/vendor/yiisoft/yii2/base/Model.php(368): yii\validators\Validator->validateAttributes(Object(craft\elements\Entry), Array)
#11 /Users/martin/Documents/xx/___dist/vendor/craftcms/cms/src/services/Sections.php(1515): yii\base\Model->validate()
#12 /Users/martin/Documents/xx/___dist/vendor/craftcms/cms/src/services/Sections.php(748): craft\services\Sections->_ensureSingleEntry(Object(craft\models\Section), Array)
#13 /Users/martin/Documents/xx/___dist/vendor/craftcms/cms/src/base/ApplicationTrait.php(1664): craft\services\Sections->handleChangedSection(Object(craft\events\ConfigEvent))
#14 /Users/martin/Documents/xx/___dist/vendor/craftcms/cms/src/services/ProjectConfig.php(1181): craft\console\Application->craft\base\{closure}(Object(craft\events\ConfigEvent))
#15 [internal function]: craft\services\ProjectConfig->handleChangeEvent(Object(craft\events\ConfigEvent))
#16 /Users/martin/Documents/xx/___dist/vendor/yiisoft/yii2/base/Component.php(628): call_user_func(Array, Object(craft\events\ConfigEvent))
#17 /Users/martin/Documents/xx/___dist/vendor/craftcms/cms/src/services/ProjectConfig.php(744): yii\base\Component->trigger('updateItem', Object(craft\events\ConfigEvent))
#18 /Users/martin/Documents/xx/___dist/vendor/craftcms/cms/src/services/ProjectConfig.php(1171): craft\services\ProjectConfig->_processConfigChangesInternal('sections.18ce40...')
#19 [internal function]: craft\services\ProjectConfig->handleChangeEvent(Object(craft\events\ConfigEvent))
#20 /Users/martin/Documents/xx/___dist/vendor/yiisoft/yii2/base/Component.php(628): call_user_func(Array, Object(craft\events\ConfigEvent))
#21 /Users/martin/Documents/xx/___dist/vendor/craftcms/cms/src/services/ProjectConfig.php(741): yii\base\Component->trigger('addItem', Object(craft\events\ConfigEvent))
#22 /Users/martin/Documents/xx/___dist/vendor/craftcms/cms/src/services/ProjectConfig.php(517): craft\services\ProjectConfig->_processConfigChangesInternal('sections.18ce40...', true, NULL)
#23 /Users/martin/Documents/xx/___dist/vendor/craftcms/cms/src/migrations/m190913_152146_update_preview_targets.php(54): craft\services\ProjectConfig->set('sections.18ce40...', Array)
#24 /Users/martin/Documents/xx/___dist/vendor/craftcms/cms/src/db/Migration.php(52): craft\migrations\m190913_152146_update_preview_targets->safeUp()
#25 /Users/martin/Documents/xx/___dist/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(744): craft\db\Migration->up()
#26 /Users/martin/Documents/xx/___dist/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(202): yii\console\controllers\BaseMigrateController->migrateUp('m190913_152146_...')
#27 /Users/martin/Documents/xx/___dist/vendor/craftcms/cms/src/console/controllers/MigrateController.php(415): yii\console\controllers\BaseMigrateController->actionUp(0)
#28 [internal function]: craft\console\controllers\MigrateController->actionUp(0)
#29 /Users/martin/Documents/xx/___dist/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#30 /Users/martin/Documents/xx/___dist/vendor/yiisoft/yii2/base/Controller.php(181): yii\base\InlineAction->runWithParams(Array)
#31 /Users/martin/Documents/xx/___dist/vendor/yiisoft/yii2/console/Controller.php(184): yii\base\Controller->runAction('up', Array)
#32 /Users/martin/Documents/xx/___dist/vendor/yiisoft/yii2/base/Module.php(534): yii\console\Controller->runAction('up', Array)
#33 /Users/martin/Documents/xx/___dist/vendor/yiisoft/yii2/console/Application.php(181): yii\base\Module->runAction('migrate/up', Array)
#34 /Users/martin/Documents/xx/___dist/vendor/craftcms/cms/src/console/Application.php(89): yii\console\Application->runAction('migrate/up', Array)
#35 /Users/martin/Documents/xx/___dist/vendor/yiisoft/yii2/console/Application.php(148): craft\console\Application->runAction('migrate/up', Array)
#36 /Users/martin/Documents/xx/___dist/vendor/yiisoft/yii2/base/Application.php(392): yii\console\Application->handleRequest(Object(craft\console\Request))
#37 /Users/martin/Documents/xx/___dist/craft(22): yii\base\Application->run()
#38 {main}
*** failed to apply m190913_152146_update_preview_targets (time: 0.617s)

1 from 32 migration was applied.

Migration failed. The rest of the migrations are canceled.

Since this seems to be related to a migration of SEOmatic, maybe @khalwat might have more insight?

brandonkelly commented 3 years ago

@martinhellwagner That error is coming from SEOmatic. Not sure what to make of it as nystudio107\seomatic\models\ MetaSiteVars::$referrer is an actual property, though:

https://github.com/nystudio107/craft-seomatic/blob/c76d832eb8f956b47b0c9176c7d9cfb2381e2174/src/models/MetaSiteVars.php#L120

khalwat commented 3 years ago

yeah I can't imagine what this could be except perhaps a somehow borked composer install?

martinhellwagner commented 3 years ago

I've cleared the Composer caches, double-checked that every plugin was indeed on its latest version, removed the vendor folder as well as the composer.lock file, and tried again – success! 😍

Wiejeben commented 3 years ago

Currently migrating a Craft 2 website to 3. The same migration failed on Craft 3.7.4 but looks like due to an unrelated issue:

#0 /var/www/vendor/yiisoft/yii2/db/BaseActiveRecord.php(324): yii\base\Component->__set('defaultPlacemen...', 'end')
#1 /var/www/vendor/craftcms/cms/src/db/ActiveRecord.php(54): yii\db\BaseActiveRecord->__set('defaultPlacemen...', 'end')
#2 /var/www/vendor/craftcms/cms/src/services/Sections.php(586): craft\db\ActiveRecord->__set('defaultPlacemen...', 'end')
#3 /var/www/vendor/craftcms/cms/src/base/ApplicationTrait.php(1668): craft\services\Sections->handleChangedSection(Object(craft\events\ConfigEvent))
#4 /var/www/vendor/craftcms/cms/src/services/ProjectConfig.php(1189): craft\console\Application->craft\base\{closure}(Object(craft\events\ConfigEvent))
#5 [internal function]: craft\services\ProjectConfig->handleChangeEvent(Object(craft\events\ConfigEvent))
#6 /var/www/vendor/yiisoft/yii2/base/Component.php(628): call_user_func(Array, Object(craft\events\ConfigEvent))
#7 /var/www/vendor/craftcms/cms/src/services/ProjectConfig.php(752): yii\base\Component->trigger('updateItem', Object(craft\events\ConfigEvent))
#8 /var/www/vendor/craftcms/cms/src/services/ProjectConfig.php(1179): craft\services\ProjectConfig->_processConfigChangesInternal('sections.8f688f...')
#9 [internal function]: craft\services\ProjectConfig->handleChangeEvent(Object(craft\events\ConfigEvent))
#10 /var/www/vendor/yiisoft/yii2/base/Component.php(628): call_user_func(Array, Object(craft\events\ConfigEvent))
#11 /var/www/vendor/craftcms/cms/src/services/ProjectConfig.php(749): yii\base\Component->trigger('addItem', Object(craft\events\ConfigEvent))
#12 /var/www/vendor/craftcms/cms/src/services/ProjectConfig.php(521): craft\services\ProjectConfig->_processConfigChangesInternal('sections.8f688f...', true, NULL)
#13 /var/www/vendor/craftcms/cms/src/migrations/m190913_152146_update_preview_targets.php(54): craft\services\ProjectConfig->set('sections.8f688f...', Array)
#14 /var/www/vendor/craftcms/cms/src/db/Migration.php(52): craft\migrations\m190913_152146_update_preview_targets->safeUp()
#15 /var/www/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(744): craft\db\Migration->up()
#16 /var/www/vendor/craftcms/cms/src/console/controllers/MigrateController.php(379): yii\console\controllers\BaseMigrateController->migrateUp('m190913_152146_...')
#17 [internal function]: craft\console\controllers\MigrateController->actionAll()
#18 /var/www/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#19 /var/www/vendor/yiisoft/yii2/base/Controller.php(181): yii\base\InlineAction->runWithParams(Array)
#20 /var/www/vendor/yiisoft/yii2/console/Controller.php(184): yii\base\Controller->runAction('all', Array)
#21 /var/www/vendor/yiisoft/yii2/base/Module.php(534): yii\console\Controller->runAction('all', Array)
#22 /var/www/vendor/yiisoft/yii2/console/Application.php(181): yii\base\Module->runAction('migrate/all', Array)
#23 /var/www/vendor/craftcms/cms/src/console/Application.php(89): yii\console\Application->runAction('migrate/all', Array)
#24 /var/www/vendor/yiisoft/yii2/console/Application.php(148): craft\console\Application->runAction('migrate/all', Array)
#25 /var/www/vendor/yiisoft/yii2/base/Application.php(392): yii\console\Application->handleRequest(Object(craft\console\Request))
#26 /var/www/craft(28): yii\base\Application->run()
#27 {main}
*** failed to apply m190913_152146_update_preview_targets (time: 0.034s)

146 from 185 migrations were applied.

I downgraded to Craft 3.6 and upgraded to 3.7 afterwards to make the migrations work.

brandonkelly commented 3 years ago

Hey @Wiejeben, can you please send your Craft 2 database backup, plus your new composer.json and composer.lock files, over to support@craftcms.com?

brandonkelly commented 3 years ago

@Wiejeben That ended up being the same error as #9624. Fixed for the next release!