magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.57k stars 9.32k forks source link

Magento 2.4.x error "Environment emulation nesting is not allowed" occurs while sending invoice email #36134

Open nhatlich994 opened 2 years ago

nhatlich994 commented 2 years ago

Preconditions and environment

Steps to reproduce

  1. Create order
  2. Go Backend > Sales > Orders
  3. Create Invoice
  4. Send Email invoice
  5. Check system.log

Expected result

Invoice send to customer without error

Actual result

system.log logged the error: Environment emulation nesting is not allowed.

The reason is \Magento\Sales\Model\Order\Email\Sender\InvoiceSender::send calls \Magento\Payment\Helper\Data::getInfoBlockHtml into (startEnvironmentEmulation and stopEnvironmentEmulation) scope. and \Magento\Payment\Helper\Data::getInfoBlockHtml is also declared (startEnvironmentEmulation and stopEnvironmentEmulation).

https://imgur.com/0YvQX4E https://imgur.com/Wd3AUhQ

Additional information

No response

Release note

No response

Triage and priority

m2-assistant[bot] commented 2 years ago

Hi @psydog-1101. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

m2-assistant[bot] commented 2 years ago

Hi @engcom-Delta. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Delta commented 2 years ago

:heavy_check_mark: Issue confirmed

Issue got reproduced in 2.4-develop branch.

Description:

While sending the invoice mail , mail was sent and an error is showing in the system.log file.

Pre-requisite:

  1. Magento 2.4.x CE

Steps to reproduce:

  1. Create a order from frontend
  2. Create a invoice for the order
  3. Send the mail from invoice
  4. Checked in system.log file

Expected result:

Invoice send to customer without error

Actual result:

In system.log file error is generated.

Screenshots:

  1. Create a order from frontend

    Screenshot 2022-09-14 at 10 45 37 AM
  2. Create a invoice for the order

    Screenshot 2022-09-14 at 10 47 16 AM
  3. Send the mail from invoice

    Screenshot 2022-09-14 at 10 48 54 AM
  4. Checked in system.log file

    Screenshot 2022-09-14 at 10 49 53 AM

Hence, confirming the issue. Thanks.

github-jira-sync-bot commented 2 years ago

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-6721 is successfully created for this GitHub issue.

m2-assistant[bot] commented 2 years ago

:white_check_mark: Confirmed by @engcom-Delta. Thank you for verifying the issue.
Issue Available: @engcom-Delta, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

hostep commented 1 year ago

This is probably a duplicate of https://github.com/magento/magento2/issues/35603 which got fixed in the meanwhile, so this issue can probably be closed?

thomas-kl1 commented 7 months ago

I'm still experiencing this issue, I need to dig a bit deeper to confirm.

Mordreak commented 7 months ago

Feels like it should be fixed in the 2.4.7 release, but I'm also still experiencing this issue on 2.4.6-p5

jamesswilliamsv commented 5 months ago

Same here and this is from 2.4.6-p6

ajung2 commented 5 months ago

Also, starting from version 2.4.6-p6, this error is difficult to debug. However, we discovered that it originates from the EmailSenderHandler.php function sendEmails() at line 134. In this line, it uses the AbstractModel $item and selects the send method by the abstract class name. So, if it is a Shipment, it goes to the deprecated ShipmentSender.php class where the nested emulation starts—first emulation at line 125 and the second emulation triggered by $this->getPaymentHtml($order) -> getInfoBlockHtml(InfoInterface $info, $storeId) at line 223. The process works, and emails are sent successfully. However, the message "nested emulation..." generates garbage in the system.log when you send 1000 emails daily to customers.

This is a core issue, and we hope for an update. Meanwhile, we are patching this message by commenting out Emulation.php line 126 temporarily to keep the log clear.

n1mbleee commented 2 months ago

any update?

atIOCrON commented 1 month ago

I'd also like an update? @engcom-Delta

erfanimani commented 3 weeks ago

Potentially a more conscientious fix would be the following:

Although I don't really know when this would ever happen unless it's some wacky coding, so maybe just removing the logger line is fine.

erfanimani commented 3 weeks ago

@atIOCrON

Looks like this was fixed in 2.4.7 onwards: https://github.com/magento/magento2/commit/4c6d47846fb00c398d36c0b8c0b1e69a417c3a79#diff-9c76aaedd0d6bac8ab3575c02f0107dca7af5ae95bb8fe11e2faf1753221f32bR147