Open dalyathan opened 1 week ago
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
The danger here :arrow_up: 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
Suggestions very welcome!
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 number