Skip to main content
Jagdish Kumawat
Founder @ Dewiride
View all authors

Fixed: "Duplicate entry for key 'order_lines.IX_order_lines_OrderId_ProductId'" When a List Repeats a Product in a Minimal API

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

A request that listed the same product twice in one order got a 500, and the log had MySQL's Duplicate entry '2-9' for key 'order_lines.IX_order_lines_OrderId_ProductId'. The database was right to refuse. But a mistake in the request should be a 400, and it shouldn't take stock and open a transaction to find out.

Fixed: "Check constraint 'CK_products_QuantityOnHand' is violated" with ExecuteUpdateAsync in EF Core and MySQL

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

Under load, sales failed with MySqlException: Check constraint 'CK_products_QuantityOnHand' is violated. and an HTTP 500. The stock never went below zero, so the constraint had worked. The problem is that a buyer who should have heard "out of stock" heard "server error".

Fixed: "Connection must be valid and open to rollback transaction" with MySql.Data

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

My log said Connection must be valid and open to rollback transaction, and that wasn't what had gone wrong. Something had failed after the commit, my catch tried to roll back a transaction that was already finished, and the new exception replaced the real one. The fix also removes code: you rarely need RollbackAsync at all.

Fixed: "The connection is already in a transaction and cannot participate in another transaction" in EF Core

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

Calling one helper method from inside a transaction failed with The connection is already in a transaction and cannot participate in another transaction. The helper had its own BeginTransactionAsync, which made sense when it was written, and it stopped making sense once something else called it inside a transaction.