I spot the issue during placing order with two different community modules installed. In short, during placing order the customer object is subscribed by custom code which utilizes newsletter module, then customer object is saved a couple times, and it results with subscribing him, unsubscribing and subscribing again.
It is a bit complicated to prepare such environment and to reproduce it so I prepared short steps which show incorrect framework behavior.
$customer = $customerRepository->getById($customerId);
$extensionAttributes = $customer->getExtensionAttributes();
var_dump($extensionAttributes->getIsSubscribed()); // returns false
Subscribe customer to newsletter:
$subscriber = $subscriberFactory->create();
$subscriber->subscribeCustomerById($customerId);
Check subscription status again:
$customer = $customerRepository->getById($customerId);
$extensionAttributes = $customer->getExtensionAttributes();
var_dump($extensionAttributes->getIsSubscribed()); // still returns false
Hi @wojtekn. Thank you for your report.
To help us process this issue please make sure that you provided the following information:
Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:
@magento-engcom-team give me $VERSION instance
where $VERSION is version tags (starting from 2.2.0+) or develop branches (for example: 2.3-develop).
For more details, please, review the Magento Contributor Assistant documentation.
@wojtekn do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?
@wojtekn,
then customer object is saved a couple times
Such problem is not observed when customer is saved using CustomerRepository.
Hi @engcom-backlog-nazar. 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:
Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.[x] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.
[x] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
[x] 4. Verify that the issue is reproducible on 2.3-develop branchDetails
- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!
[x] 5. Verify that the issue is reproducible on 2.2-develop branch. Details
- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x
[x] 6. Add label Issue: Confirmed once verification is complete.
[x] 7. Make sure that automatic system confirms that report has been added to the backlog.
Hi @wojtekn, Hi @orlangur thank you for your report, in first time when i run this on console command i'm have false, but another time always return true, so problem with registry, when you load customer from repository you have no choise to load from.

@engcom-backlog-nazar Thank you for verifying the issue. Based on the provided information internal tickets MAGETWO-96607, MAGETWO-96608 were created
@engcom-backlog-nazar correct, I noticed from subscribeCustomerById implementation that there is no way customer instance may be reloaded. What I was saying is that it is quite easy to circumvent in third-party code.
@orlangur we need some additional options like in productRepository force Reload = true.

@engcom-backlog-nazar introducing such flags is _really_ lame. It would be better if invalidation occurs somewhere inside subscribeCustomerById, we already have push method to achieve this.
@engcom-backlog-nazar I think changing getById implementation to preserve extension attributes also makes sense. It wouldn't solve my use case, but it would fix other ones. Eg. I could write plugin for subscribeCustomerById and fill extension attribute there instead of removing this variable caching in the core file patch.
@orlangur it makes sense IMO.
Hi @milindsingh. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if your want to validate it one more time, please, go though the following instruction:
Component: XXXXX label(s) to the ticket, indicating the components it may be related to.[ ] 2. Verify that the issue is reproducible on 2.3-develop branchDetails
- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!
[ ] 3. Verify that the issue is reproducible on 2.2-develop branch. Details
- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x
[ ] 4. If the issue is not relevant or is not reproducible any more, feel free to close it.
Most helpful comment
@engcom-backlog-nazar introducing such flags is _really_ lame. It would be better if invalidation occurs somewhere inside
subscribeCustomerById, we already havepushmethod to achieve this.