dotmailer / dotmailer-magento2-extension

The official Dotdigital for Magento2 extension
https://dotdigital.com/integrations/magento
MIT License
48 stars 64 forks source link

Error on setup:upgrade after upgrading to 4.24.1 #626

Closed VictorSoaresRedstage closed 4 months ago

VictorSoaresRedstage commented 5 months ago

Hello,

Store running on Adobe Commerce on PREM - 2.4.5-p6, with 2 websites, 2 stores and 2 store views.

I'm upgrading DotDigital extension from 4.21.1 to 4.24.1 and I'm facing an issue while running setup:upgrade on STAGING (no issues locally):

Magento\Store\Model\App\Emulation::_restoreInitialDesign(): Argument #1 ($initialDesign) must be of type array, null given, called in /chroot/home/project/dev/magento/vendor/magento/module-store/Model/App/Emulation.php on line 182#0 /chroot/home/project/dev/magento/vendor/magento/module-store/Model/App/Emulation.php(182): Magento\Store\Model\App\Emulation->_restoreInitialDesign(NULL)
#1 /chroot/home/project/dev/magento/vendor/dotdigital/dotdigital-magento2-extension/Model/Connector/ContactData/Customer.php(506): Magento\Store\Model\App\Emulation->stopEnvironmentEmulation()
#2 /chroot/home/project/dev/magento/generated/code/Dotdigitalgroup/Email/Model/Connector/ContactData/Customer/Interceptor.php(302): Dotdigitalgroup\Email\Model\Connector\ContactData\Customer->getSubscriberStatus()
#3 /chroot/home/project/dev/magento/vendor/dotdigital/dotdigital-magento2-extension/Model/Connector/ContactData.php(193): Dotdigitalgroup\Email\Model\Connector\ContactData\Customer\Interceptor->getSubscriberStatus()
#4 /chroot/home/project/dev/magento/vendor/magento/framework/Interception/Interceptor.php(58): Dotdigitalgroup\Email\Model\Connector\ContactData->setContactData()
#5 /chroot/home/project/dev/magento/vendor/magento/framework/Interception/Interceptor.php(138): Dotdigitalgroup\Email\Model\Connector\ContactData\Customer\Interceptor->___callParent('setContactData', Array)
#6 /chroot/home/project/dev/magento/vendor/magento/framework/Interception/Interceptor.php(153): Dotdigitalgroup\Email\Model\Connector\ContactData\Customer\Interceptor->Magento\Framework\Interception\{closure}()
#7 /chroot/home/project/dev/magento/generated/code/Dotdigitalgroup/Email/Model/Connector/ContactData/Customer/Interceptor.php(329): Dotdigitalgroup\Email\Model\Connector\ContactData\Customer\Interceptor->___callPlugins('setContactData', Array, Array)
#8 /chroot/home/project/dev/magento/vendor/dotdigital/dotdigital-magento2-extension/Model/Connector/ContactData/Customer.php(152): Dotdigitalgroup\Email\Model\Connector\ContactData\Customer\Interceptor->setContactData()
#9 /chroot/home/project/dev/magento/generated/code/Dotdigitalgroup/Email/Model/Connector/ContactData/Customer/Interceptor.php(23): Dotdigitalgroup\Email\Model\Connector\ContactData\Customer->init(Object(Magento\Customer\Model\Customer\Interceptor), Array)
#10 /chroot/home/project/dev/magento/vendor/dotdigital/dotdigital-magento2-extension/Model/Sync/Customer/Exporter.php(144): Dotdigitalgroup\Email\Model\Connector\ContactData\Customer\Interceptor->init(Object(Magento\Customer\Model\Customer\Interceptor), Array)
#11 /chroot/home/project/dev/magento/vendor/dotdigital/dotdigital-magento2-extension/Model/Sync/Automation/DataField/DataFieldCollector.php(101): Dotdigitalgroup\Email\Model\Sync\Customer\Exporter->export(Array, Object(Magento\Store\Model\Website\Interceptor))
#12 /chroot/home/project/dev/magento/vendor/dotdigital/dotdigital-magento2-extension/Model/Sync/Automation/ContactManager.php(91): Dotdigitalgroup\Email\Model\Sync\Automation\DataField\DataFieldCollector->collectForCustomer(Object(Dotdigitalgroup\Sms\Model\SmsContact), 2)
#13 /chroot/home/project/dev/magento/vendor/dotdigital/dotdigital-magento2-extension/Model/Sync/Automation/AutomationProcessor.php(172): Dotdigitalgroup\Email\Model\Sync\Automation\ContactManager->prepareDotdigitalContact(Object(Dotdigitalgroup\Sms\Model\SmsContact), Object(Magento\Newsletter\Model\Subscriber\Interceptor), Array, 'subscriber_auto...')
#14 /chroot/home/project/dev/magento/vendor/dotdigital/dotdigital-magento2-extension/Model/Sync/Automation/AutomationProcessor.php(115): Dotdigitalgroup\Email\Model\Sync\Automation\AutomationProcessor->assembleDataForEnrolment(Object(Dotdigitalgroup\Email\Model\Automation))
#15 /chroot/home/project/dev/magento/vendor/dotdigital/dotdigital-magento2-extension/Model/Sync/Automation.php(73): Dotdigitalgroup\Email\Model\Sync\Automation\AutomationProcessor->process(Object(Dotdigitalgroup\Email\Model\ResourceModel\Automation\Collection\Interceptor))
#16 /chroot/home/project/dev/magento/vendor/dotdigital/dotdigital-magento2-extension/Setup/Patch/Data/ProcessPendingAutomations.php(42): Dotdigitalgroup\Email\Model\Sync\Automation->sync()
#17 /chroot/home/project/dev/magento/vendor/magento/framework/Setup/Patch/PatchApplier.php(162): Dotdigitalgroup\Email\Setup\Patch\Data\ProcessPendingAutomations->apply()
#18 /chroot/home/project/dev/magento/setup/src/Magento/Setup/Model/Installer.php(1095): Magento\Framework\Setup\Patch\PatchApplier->applyDataPatch('Dotdigitalgroup...')
#19 /chroot/home/project/dev/magento/setup/src/Magento/Setup/Model/Installer.php(961): Magento\Setup\Model\Installer->handleDBSchemaData(Object(Magento\Setup\Module\DataSetup), 'data', Array)
#20 /chroot/home/project/dev/magento/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php(147): Magento\Setup\Model\Installer->installDataFixtures(Array, true)
#21 /chroot/home/project/dev/magento/vendor/symfony/console/Command/Command.php(255): Magento\Setup\Console\Command\UpgradeCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 /chroot/home/project/dev/magento/vendor/symfony/console/Application.php(1021): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 /chroot/home/project/dev/magento/vendor/symfony/console/Application.php(275): Symfony\Component\Console\Application->doRunCommand(Object(Magento\Setup\Console\Command\UpgradeCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#24 /chroot/home/project/dev/magento/vendor/magento/framework/Console/Cli.php(116): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 /chroot/home/project/dev/magento/vendor/symfony/console/Application.php(149): Magento\Framework\Console\Cli->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#26 /chroot/home/project/dev/magento/bin/magento(23): Symfony\Component\Console\Application->run()
#27 {main}

PHP Fatal error:  Uncaught Exception: User Error: Some transactions have not been committed or rolled back in /chroot/home/project/dev/magento/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php on line 4067 in /chroot/home/project/dev/magento/vendor/magento/framework/App/ErrorHandler.php:62
Stack trace:
#0 [internal function]: Magento\Framework\App\ErrorHandler->handler(256, 'Some transactio...', '/chroot/home/de...', 4067)
#1 /chroot/home/project/dev/magento/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php(4067): trigger_error('Some transactio...', 256)
#2 [internal function]: Magento\Framework\DB\Adapter\Pdo\Mysql->__destruct()
#3 {main}
  thrown in /chroot/home/project/dev/magento/vendor/magento/framework/App/ErrorHandler.php on line 62

Issue seems to be on ProcessPendingAutomations data patch.

Can you help me?

Thank you, Victor Soares.

VictorSoaresRedstage commented 5 months ago

update: I'm seeing an error on logs when the issue happens on "vendor/dotdigital/dotdigital-magento2-extension/Model/Connector/ContactData/Customer.php::getSubscriberStatus":

report.ERROR: Environment emulation nesting is not allowed.

sta1r commented 5 months ago

Hi. This patch is designed to deal with any 'pending' automation rows in email_automation once the old ddg_automation_status cron is no longer running. As part of automation sync, we ensure that contacts are sent to Dotdigital, with all their required data fields, prior to enrolment. When we fetch data fields, we have this case where we need to use Magento\Store\Model\App\Emulation to ensure we get the right store-scoped subscriber status value.

It appears that we're not allowed to use Emulation during the upgrade process. I get:

"Magento\\Framework\\Exception\\LocalizedException: Area code is not set

In my test (2.4.7), the exception is caught in the sync script, and the process completes - but seemingly for you that is not happening.

The steps for you to resolve this are:

  1. Run this query to manually mark the patch as applied:
    INSERT INTO `patch_list` (patch_name) VALUES ('Dotdigitalgroup\Email\Setup\Patch\Data\ProcessPendingAutomations');
  2. Complete the upgrade
  3. Run the automation sync manually:
    bin/magento dotdigital:sync Automation
sta1r commented 5 months ago

Quick update on this: we'll be replacing usage of Emulation in Model/Connector/ContactData/Customer. So I'd advise waiting for 4.24.2 (coming this week) before deploying to production.

VictorSoaresRedstage commented 5 months ago

Quick update on this: we'll be replacing usage of Emulation in Model/Connector/ContactData/Customer. So I'd advise waiting for 4.24.2 (coming this week) before deploying to production.

Got it - thank you for the updates!