Repository navigation
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
damaz91
left a comment
There was a problem hiding this comment.
Thanks @arjun2075 for implementing cart expiry checks and boundary tests!
Alongside resolving the commit author email for cla/google (see #273), could we also extend the is_cart_expired check to CartService.update_cart (PUT /carts/{id}) and CartService.cancel_cart (POST /carts/{id}/cancel) in services/cart_service.py?
- In
cart.md, Cart status is binary (exists/not found). Right now,PUT /carts/{id}on an expired cart still returns200 OKwhile preserving the pastexisting.expires_at, so a caller gets200 OKon update followed immediately by404 RESOURCE_NOT_FOUNDonGET /carts/{id}or checkout conversion (andPOST /carts/{id}/cancelsimilarly returns200 OKon an expired cart). Checkingif not existing_data or is_cart_expired(existing_data):inupdate_cartandcancel_cartkeeps all Cart endpoints consistent. - Optional minor hardening: In
is_cart_expired, normalizing both"Z"and lowercase"z"(RFC 3339 allows both) and defaultingparsed.tzinfo is Nonetodatetime.timezone.utcguards against aTypeError(500) if a naive ISO string ever lands in storage.
Return 404 RESOURCE_NOT_FOUND for expired cart reads, updates, cancellations, and cart-to-checkout conversion. Check expiry before any mutation or idempotency record is persisted. Normalize both RFC 3339 UTC suffixes and treat naive stored expiry timestamps as UTC. Cover expiry boundaries, timestamp formats, expired mutations without state changes, and successful unexpired paths.
029618f to
ba20fb2
Compare
damaz91
left a comment
There was a problem hiding this comment.
Thanks @arjun2075 for extending the expiry check to update_cart and cancel_cart, hardening is_cart_expired across UTC suffixes and naive timestamps, and adding thorough state-preservation tests! Everything looks clean and passes the server and conformance suites — LGTM.
Problem
A cart past its
expires_atwas still returned by GET, accepted by update and cancel, and convertible into a checkout. Updating an expired cart returned 200 while retaining the past expiry, followed immediately by 404 on GET or conversion.Fix
Add
is_cart_expiredand use it inCartService.get_cart,update_cart,cancel_cart, and cart-to-checkout conversion. Expired carts receive the existing 404RESOURCE_NOT_FOUNDUCP error envelope. Update and cancel check expiry before changing the cart or recording a new idempotency result.A cart expires when
expires_at <= now; a cart without an expiry never expires. Normalize bothZandzUTC suffixes for Python 3.10 compatibility, preserve explicit timezone offsets, and interpret naive stored timestamps as UTC.This follows the Cart specification's binary exists/not-found model and its treatment of expired carts as not found, checked against tag
v2026-04-08.Regression coverage
The added update/cancel regression returned 200 before the review fix; lowercase UTC and naive timestamp cases also failed before hardening.
Validation
Existing idempotency replay behavior and reuse of an already-existing incomplete checkout are unchanged.