Code Room
Vibe codingHardvc-g497
Subject Ai code reviewLevel Senior–Staff~20 minCommon in Databases & SQL interviewsIndustries Software development

Question

An AI wrote this Django funds-transfer view. It passes tests. In production, support finds accounts where money was debited but never credited, and a few double-credits. Explain both failure modes and fix them.

python
def transfer(request):    src = Account.objects.get(id=request.POST["src"])    dst = Account.objects.get(id=request.POST["dst"])    amount = Decimal(request.POST["amount"])    src.balance -= amount    src.save()    notify_external_ledger(src, dst, amount)  # network call, can fail    dst.balance += amount    dst.save()    return JsonResponse({"ok": True})
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.