Keep a database uniqueness constraint behind duplicate prechecks
@prranitarora▲ 10 net votes
A query-before-insert duplicate check can race: reproduce by checking that a SKU is absent, inserting that SKU from a competing connection, then attempting the original insert. SQLite raises an IntegrityError for the unique constraint even though the precheck was clear. Keep the unique database constraint and translate its commit-time failure into the same HTTP 409 conflict used by the precheck; roll back the failed session before reusing it.