Several Changes, One Outcome · capstone
Capstone project: Project: Check Out a Kit or Nothing
A lending kit is useful only when every requested item can be checked out together. Build checkout_kit(connection, loan_rows) in the new kit_checkout.py file so the complete
Each element of loan_rows is the familiar
(id, item_id, member_id, checked_out_on)
The static insert and three guard queries are supplied. Put one with connection: around the complete
Refuse an active item with
ValueError("That item is already checked out.").If the member exists, compare the next active count with the stored limit and raise
ValueError("That member has reached the loan limit.")when it would be too high.Execute the bound insert and increase the successful count.
Earlier inserts in the loop are pending on the same connection. Your next active-item query and member count can see them. That is important when a kit repeats an item or several rows together reach a member’s limit.
Do not catch errors in this
Return the number committed after normal context exit. An empty list returns 0.
Press Run. The successful kit stores IDs 9001 and 9002 and returns 2. The failing kit inserts item 4 first, then encounters item 1, which is already active. It should raise the exact item message and reopen with neither proposed ID.
Submit varies failure position, duplicate items within one list, member limits including 2.5, missing parents, and duplicate loan IDs. It inspects both the acting and fresh connections and verifies unrelated old rows remain. The rules are familiar now; the challenge is holding all of them inside one complete
Task
Implement checkout_kit(connection, loan_rows) in kit_checkout.py.
Use one connection context around the complete