You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Which plugin/repository is the issue about?
@pinelab/vendure-plugin-invoices
Describe the bug
When concurrent invoice generation takes place, invoice generations fails. To Reproduce
Steps to reproduce the behavior:
Create a Draft Order
Complete at the draft order and add payment to it.
Since the plugin starts generating an invoice when an order is placed, immediately try to create a concurrent invoice generation by clicking Regenerate Invoice button in the order-detail button.
Notice that this fails by throwing the attached error.
Expected behavior
invoices should have been regenerated successfully. Screenshots
Environment
NodeJS version: 21
Vendure version: 2.1.2
Plugin version 2.3.2
Database sqljs, mysql
Any other version numbers from the environment you're using
Additional context
The invoice number generation needs to either be transactional scoped or we should use sequences to generate the invoice number
The text was updated successfully, but these errors were encountered:
The problem occurs because the query in this function doesn't lock the invoice table when it executes. But rather than using locks in entire tables, I think it is better to use sequences to generate the invoiceNumber
Hmm good catch. I thought we fixed this one. Can we somehow leverage typeorm to do the auto increment? The difficulty here I think is that the unique constraint should be a combination of invoiceNumber and channelId, because it's fine if different channels have the same invoice numbers.
An alternative is to rewrite the code
Get the latest invoice number
Immediately insert a row with the incremented number, before doing anything else
If a unique constraint fails, we try again (max 3 retries?), until we have a row inserted in the DB. This way we are sure that we have 'reserved' an invoice number.
After that, we generate the PDF and save the storage reference.
The danger here ⬆️ is that the PDF generation can fail, and we have reserved an invoice number for a PDF that was never created.
Edit: After thinking about it, locking the table during the entire PDF generation process seems like a safe solution. PDF's are generated in the worker, so a bit of a delay during concurrent generations isn't really a problem
Which plugin/repository is the issue about?
@pinelab/vendure-plugin-invoices
Describe the bug
When concurrent invoice generation takes place, invoice generations fails.
To Reproduce
Steps to reproduce the behavior:
Regenerate Invoice
button in theorder-detail
button.Expected behavior
invoices should have been regenerated successfully.
Screenshots
Environment
Additional context
The invoice number generation needs to either be transactional scoped or we should use
sequences
to generate the invoice numberThe text was updated successfully, but these errors were encountered: