Code Room
Vibe codingHardvc-g504
Subject Ai code reviewLevel Senior~18 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

An AI wrote this DRF endpoint to apply a discount to an order. The serializer 'validates' the payload. Finance discovers orders with negative totals and 300% discounts. Explain why validation didn't stop it and fix it.

python
class DiscountSerializer(serializers.Serializer):    percent = serializers.FloatField()    reason = serializers.CharField() @api_view(["POST"])def apply_discount(request, order_id):    s = DiscountSerializer(data=request.data)    s.is_valid(raise_exception=True)    order = Order.objects.get(id=order_id)    order.total = order.total * (1 - s.validated_data["percent"] / 100)    order.save()    return Response({"total": str(order.total)})
What a strong answer looks like

Treat the AI’s output as a draft to verify, not an answer to trust. Name the specific flaw and the input that triggers it, say how you’d catch it — tests, edge cases, reading critically — and how you’d re-prompt or decompose to get it right.

Describe your solution

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.