-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Fix best practice "Asynchronous order data processing" for auto invoiced orders #36224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix best practice "Asynchronous order data processing" for auto invoiced orders #36224
Conversation
Hi @convenient. Thank you for your contribution
❗ Automated tests can be triggered manually with an appropriate comment:
You can find more information about the builds here ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review. For more details, review the Magento Contributor Guide documentation. 🕙 You can find the schedule on the Magento Community Calendar page. 📞 The triage of Pull Requests 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. ✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel |
@magento run all tests |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time. |
@magento run all tests |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time. |
@magento run all tests |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time. |
@magento run Functional Tests B2B, Functional Tests EE, Integration Tests |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time. |
@magento run Functional Tests B2B, Functional Tests EE |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time. |
@magento create issue |
@magento give me 2.4-develop instanc |
@magento give me 2.4-develop instance |
Hi @engcom-Lima. Thank you for your request. I'm working on Magento instance for you. |
Hi @engcom-Lima, here is your Magento Instance: https://e93c387a59b66ac7b857984de65d9660.instances.magento-community.engineering |
Hi @convenient , Thanks for your contribution and collaboration. I have tried to reproduce the issue but issue is not reproducible to me. Steps to reproduce:
I am able place an order successfully. If something I am missing please provide me information and also try to test it in latest Thanks |
@engcom-Lima do you have direct access to the code base? Did you apply the hack that makes a mess when the indexing occurs? I mentioned this because I don't know what your crons / indexers are like on your test system
|
Thanks @engcom-Lima , for what its worth I've had this patched into a production instance for a few weeks now and seems to be working well. No longer getting |
Description
Configuring order grid async indexing is meant to be a pretty quick win.
Configuring this value means we can still take orders and let the cron job be responsible for populating the admin tables, but unfortunately it only works when an order is not automatically invoiced during creation (so for us this breaks when used with paypal/stripe/etc)
Toggling the setting
dev/grid/async_indexing=1
is meant to ensure we do not populatesales_order_grid
,sales_invoice_grid
, and other grid tables during the synchronous request in which the order is being placed as any failure to insert into these admin panel grids could cause the actual order to fail and rollback with an error like soI haven't traced this back fully through the git history, but I believe this has been broken for a while.
To reproduce and testing
I have reproduced this on a vanilla installation of 2.4.5, you need a payment method which automatically creates the invoice when placing the order (for us on production this is Paypal/Stripe/etc) but for these test purposes I'll use the free checkout option.
The configuration
Also you should create a simple product that is in stock for purchasing, with a price of 0.00.
For the purposes of a quick test (and because I don't know if you have your crons running in your Magento internal test instances) I hacked up the grid reindexing code to throw an exception, we should be able to place the order and see the success page, verifying that we never try to reindex the grid during the place order action.
To reproduce the issue
Expected result:
sales_order_grid
orsales_invoice_grid
for your orderActual result:
screen-recording-2022-09-30-at-120351_t3skb0cQ.mp4
When you take this approach you can see in the logs a stack trace showing the piece of code that is attempting to synchronously reindex the grid tables despite the flag being set.
The issue is this plugin which attempts to attach addresses to newly created invoices, and also reindex the grid.
magento2/app/code/Magento/Sales/Model/Order/Invoice/Plugin/AddressUpdate.php
Lines 52 to 74 in d6ff7b7
Seeing as we're creating the invoice during the same time as we're creating the order, this causes the
dev/grid/async_indexing
flag to not be respected.Proposed Solution
I believe using the same kind of logic that exists in
Magento\Sales\Model\GridAsyncInsert
andMagento\Sales\Model\GridSyncInsertObserver
should suffice, which is what i've put in this pull request.I've not yet chased down the static/unit/integration testing etc, as I wanted to get this out there and get a discussion going before burning any more time on this, if this solution looks acceptable I'll tidy thing up a bit.
Any input / comments / criticisms? I'd really like this patched in before we get into Black Friday / Christmas and any feedback is appreciated.
Contribution checklist (*)
Resolved issues: