Skip to main content

273 posts tagged with "Fixes"

Fixes for Common Issues and Errors

View All Tags

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.