question 466 Secure Python · medium
The sort that never sorts
A developer "secured" the product listing by passing the sort column as a placeholder. No injection is possible any more, but customers complain that sorting by price or rating does nothing: products always come back in the order they were added. Fix top_products so the chosen sort really works and stays safe.
Function
top_products(conn, sort, limit)sort
"price" (cheapest first), "rating" (best first) or "name" (A to Z); anything else raises ValueErrorReturnsup to
limit SKUs in that order; ties are broken by SKU