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.5k stars 9.31k forks source link

No such entity with addressId, occurs randomly on visitors browser. System Log Generated #15115

Closed InternetMedicineMan closed 3 years ago

InternetMedicineMan commented 6 years ago

We've been having an issue on our 2.2.3 installation in Production. On occasion a visitor will report they have this System Log Generated error show up instead of the web page. I've managed to get it myself just a couple times. Every single time when you go to the filesystem and check the report it reports the following:

{"0":"No such entity with addressId = 45879","1":"#0 \/chroot\/home\/wonderci\/retailer.wondercide.com\/html\/vendor\/magento\/module-customer\/Model\/AddressRegistry.php(49): Magento\Framework\Exception\NoSuchEntityException::singleField('addressId', '45879')

1 \/chroot\/home\/wonderci\/retailer.wondercide.com\/html\/vendor\/magento\/module-customer\/Model\/ResourceModel\/AddressRepository.php(166): Magento\Customer\Model\AddressRegistry->retrieve('45879')

2 \/chroot\/home\/wonderci\/retailer.wondercide.com\/html\/vendor\/magento\/module-persistent\/Observer\/EmulateCustomerObserver.php(105): Magento\Customer\Model\ResourceModel\AddressRepository->getById('45879')

</end Fragment>

The addressID is different every time. And the only way to fix it for that person, is to just clear the cookies. Once you clear your cookies for the domain everything works perfectly fine again. It almost seems like something on the cookies is getting corrupt. It's pretty rare that it happens but we have a busy store, so rare is still 2-5 times a day.

Preconditions

  1. Magento 2.2.3
  2. PHP v 7.0.23
  3. Percona
  4. Managed Magento server at Nexcess

Steps to reproduce

I have not managed to figure out reliable steps to reproduce. Appears to be random

Expected result

  1. It shouldn't produce an error?

Actual result

{"0":"No such entity with addressId = 45879","1":"#0 \/chroot\/home\/wonderci\/retailer.wondercide.com\/html\/vendor\/magento\/module-customer\/Model\/AddressRegistry.php(49): Magento\Framework\Exception\NoSuchEntityException::singleField('addressId', '45879')\n#1 \/chroot\/home\/wonderci\/retailer.wondercide.com\/html\/vendor\/magento\/module-customer\/Model\/ResourceModel\/AddressRepository.php(166): Magento\Customer\Model\AddressRegistry->retrieve('45879')\n#2 \/chroot\/home\/wonderci\/retailer.wondercide.com\/html\/vendor\/magento\/module-persistent\/Observer\/EmulateCustomerObserver.php(105): Magento\Customer\Model\ResourceModel\AddressRepository->getById('45879')\n#3 \/chroot\/home\/wonderci\/retailer.wondercide.com\/html\/vendor\/magento\/framework\/Event\/Invoker\/InvokerDefault.php(72): Magento\Persistent\Observer\EmulateCustomerObserver->execute(Object(Magento\Framework\Event\Observer))\n#4 \/chroot\/home\/wonderci\/retailer.wondercide.com\/html\/vendor\/magento\/framework\/Event\/Invoker\/InvokerDefault.php(60): Magento\Framework\Event\Invoker\InvokerDefault->_callObserverMethod(Object(Magento\Persistent\Observer\EmulateCustomerObserver), Object(Magento\Framework\Event\Observer))\n#5 \/chroot\/home\/wonderci\/retailer.wondercide.com\/html\/vendor\/magento\/framework\/Event\/Manager.php(66): Magento\Framework\Event\Invoker\InvokerDefault->dispatch(Array, Object(Magento\Framework\Event\Observer))\n#6 \/chroot\/home\/wonderci\/retailer.wondercide.com\/html\/generated\/code\/Magento\/Framework\/Event\/Manager\/Proxy.php(95): Magento\Framework\Event\Manager->dispatch('controller_acti...', Array)\n#7 \/chroot\/home\/wonderci\/retailer.wondercide.com\/html\/vendor\/magento\/framework\/App\/Action\/Action.php(96): Magento\Framework\Event\Manager\Proxy->dispatch('controller_acti...', Array)\n#8 \/chroot\/home\/wonderci\/retailer.wondercide.com\/html\/vendor\/magento\/framework\/Interception\/Interceptor.php(58): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http))\n#9 \/chroot\/home\/wonderci\/retailer.wondercide.com\/html\/vendor\/magento\/framework\/Interception\/Interceptor.php(138): Magento\Cms\Controller\Index\Index\Interceptor->callParent('dispatch', Array)\n#10 \/chroot\/home\/wonderci\/retailer.wondercide.com\/html\/vendor\/magento\/framework\/Interception\/Interceptor.php(153): Magento\Cms\Controller\Index\Index\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))\n#11 \/chroot\/home\/wonderci\/retailer.wondercide.com\/html\/generated\/code\/Magento\/Cms\/Controller\/Index\/Index\/Interceptor.php(39): Magento\Cms\Controller\Index\Index\Interceptor->callPlugins('dispatch', Array, Array)\n#12 \/chroot\/home\/wonderci\/retailer.wondercide.com\/html\/vendor\/magento\/framework\/App\/FrontController.php(55): Magento\Cms\Controller\Index\Index\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))\n#13 \/chroot\/home\/wonderci\/retailer.wondercide.com\/html\/vendor\/magento\/framework\/Interception\/Interceptor.php(58): Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))\n#14 \/chroot\/home\/wonderci\/retailer.wondercide.com\/html\/vendor\/magento\/framework\/Interception\/Interceptor.php(138): Magento\Framework\App\FrontController\Interceptor->callParent('dispatch', Array)\n#15 \/chroot\/home\/wonderci\/retailer.wondercide.com\/html\/vendor\/magento\/module-store\/App\/FrontController\/Plugin\/RequestPreprocessor.php(94): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))\n#16 \/chroot\/home\/wonderci\/retailer.wondercide.com\/html\/vendor\/magento\/framework\/Interception\/Interceptor.php(135): Magento\Store\App\FrontController\Plugin\RequestPreprocessor->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))\n#17 \/chroot\/home\/wonderci\/retailer.wondercide.com\/html\/vendor\/magento\/module-page-cache\/Model\/App\/FrontController\/BuiltinPlugin.php(69): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))\n#18 \/chroot\/home\/wonderci\/retailer.wondercide.com\/html\/vendor\/magento\/framework\/Interception\/Interceptor.php(135): Magento\PageCache\Model\App\FrontController\BuiltinPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))\n#19 \/chroot\/home\/wonderci\/retailer.wondercide.com\/html\/vendor\/magento\/framework\/Interception\/Interceptor.php(153): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))\n#20 \/chroot\/home\/wonderci\/retailer.wondercide.com\/html\/generated\/code\/Magento\/Framework\/App\/FrontController\/Interceptor.php(26): Magento\Framework\App\FrontController\Interceptor->callPlugins('dispatch', Array, NULL)\n#21 \/chroot\/home\/wonderci\/retailer.wondercide.com\/html\/vendor\/magento\/framework\/App\/Http.php(135): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))\n#22 \/chroot\/home\/wonderci\/retailer.wondercide.com\/html\/generated\/code\/Magento\/Framework\/App\/Http\/Interceptor.php(24): Magento\Framework\App\Http->launch()\n#23 \/chroot\/home\/wonderci\/retailer.wondercide.com\/html\/vendor\/magento\/framework\/App\/Bootstrap.php(256): Magento\Framework\App\Http\Interceptor->launch()\n#24 \/chroot\/home\/wonderci\/wondercide.com\/html\/index.php(43): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor))\n#25 {main}","url":"\/","script_name":"\/index.php"}

Additional Information

The issue is not trivial and reproducible only in specific condition(s) or situation. Here is the summary based investigation and comments

Swahjak commented 3 years ago

Experiencing similar issues on Magento 2.4.1, why was this issue closed? As it is obviously still unresolved (based on the comments and experience).

sdzhepa commented 3 years ago

Seems this issue has been closed by mistake Reopen it not fixed yet

sidolov commented 3 years ago

Hi here! I have investigated an issue a little bit, agree that it's really hard to reproduce it, but I found steps to reproduce with some direct changes in the DB. And thank you guys for your comments, it helped a lot!

So, the following steps may help you to reproduce the issue:

  1. Configure persistent shopping cart with the following settings

    Screen Shot 2020-12-08 at 12 45 34
  2. Create a new customer and define default shipping and billing addresses.

  3. Log out

  4. Log in with "Remember me" checkbox applied.

  5. Go to customer_entity DB table and change default_billing and default_shipping ids to not existing ones.

  6. Log out

You will get a No such entity with addressId = error, caused by an exception in https://github.com/magento/magento2/blob/a31f4a35c018ad09654e5bd5871086b73fbd3d2d/app/code/Magento/Persistent/Observer/EmulateCustomerObserver.php#L90

To be honest, I don't know what caused the incorrect address id in the table, probably during the order submission process something went wrong, and customer addresses weren't saved, but the customer model has been updated at this moment.

So, the easy fix is to wrap https://github.com/magento/magento2/blob/a31f4a35c018ad09654e5bd5871086b73fbd3d2d/app/code/Magento/Persistent/Observer/EmulateCustomerObserver.php#L90 call into the try-catch block and update customer record/ignore incorrect address id.

The proper fix is to identify the root cause of the incorrect address ids and handle it to avoid incorrect data in DB at all.

sdzhepa commented 3 years ago

The issue was investigated and prioritized today during a public triage meeting.

magento-engcom-team commented 3 years ago

:white_check_mark: Confirmed by @sdzhepa Thank you for verifying the issue. Based on the provided information internal tickets MC-39765 were created

Issue Available: @sdzhepa, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

zakdma commented 3 years ago

@magento i am working on it

magento-engcom-team commented 3 years ago

Hi @InternetMedicineMan, @zakdma.

Thank you for your report and collaboration!

The related internal Jira ticket MC-39765 was closed as Fixed.

The fix will be available with the upcoming 2.4.3 release.

rtshshukla commented 3 years ago

@magento i am working on it

Hey, can I get the changes you have done for this because I'm facing the same issue on my site. magento version 2.3.5-p2 EE

m2-assistant[bot] commented 3 years ago

Hi @rtshshukla! :wave: Thank you for collaboration. Only members of Community Contributors Team are allowed to be assigned to the issue. Please use @magento add to contributors team command to join Contributors team.

hostep commented 3 years ago

@rtshshukla, you can often use github's search functionality to find commits related to that ticket number they mentioned before, like this: https://github.com/magento/magento2/search?q=MC-39765&type=commits

Hope this helps 🙂

nickpiro commented 3 years ago

We're experiencing this after upgrading from 2.3.0 CE to 2.3.6 CE. I don't see any Persistent settings in our admin section, confused why there would be a persistent issue when it seems Persistent is no longer on CE? Or am I wrong?

Why is this closed? We updated the file EmulateCustomerObserver.php with the latest file and that still has not corrected the issue.

Do we first need to run the Db query to clear the tables?

This is happening on a live site to customers all day. Anyone?

nickpiro commented 3 years ago

It seems to happen to logged in users when they have neither default billing address nor do they have default shipping address.

mrtuvn commented 3 years ago

@sdzhepa @zakdma Can you share commit related with PR for the fix ? cc: @duckchip can this issue reproducible in 2.4-develop

hostep commented 3 years ago

@mrtuvn: Commits tagged with MC-39765: https://github.com/magento/magento2/search?q=MC-39765&type=commits (I already mentioned this 4 posts ago 😉 )

@nickpiro, the Persistent module is definitely still a default Magento module in 2.3.6 (make sure you didn't disable this module in your app/etc/config.php file or removed it with a replace trick in your composer.json file)

mrtuvn commented 3 years ago

oh i don't recognise that! Thank you for mention Btw not sure this problem can be experience or present again after apply fixes in 2.4.2, 2.4.1?

broadmargin commented 3 years ago

Is there a patch for previous versions of magento? I see there are 7 commits with multiple modified files. What is the complete solution for this regarding previous versions of magento?

hostep commented 3 years ago

@broadmargin: there seem to be 2 merge commits:

The second one only contains some minor changes to a unit test. If you don't care about unit tests, you will probably have enough with the first commit and can make a patch out of that one commit.

Or alternatively, you could try to setup a clone of the magento2 git repo, checking out the tag of the Magento version you are working on, and then cherry-picking with the -n flag, the following non-merge commits (and manually solving merge conflicts if you run into them):

And then creating a patch out of the uncommited changes, which should result in the same patch as those merge commits.