Skip to content

fix(rest/python): return not found for expired carts - #275

Open
arjun2075 wants to merge 1 commit into
Universal-Commerce-Protocol:mainfrom
arjun2075:fix/python-expired-cart
Open

arjun2075 wants to merge 1 commit into
Universal-Commerce-Protocol:mainfrom
arjun2075:fix/python-expired-cart

Conversation

@arjun2075

@arjun2075 arjun2075 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A cart past its expires_at was 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_expired and use it in CartService.get_cart, update_cart, cancel_cart, and cart-to-checkout conversion. Expired carts receive the existing 404 RESOURCE_NOT_FOUND UCP 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 both Z and z UTC 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

  • Expired GET returns 404.
  • Expired cart-to-checkout conversion returns 404 and creates no checkout.
  • Expired update and cancel with fresh idempotency keys return 404, preserve the stored cart, and create no idempotency record.
  • A future expiry still permits reads and conversion; the existing lifecycle test covers successful update and cancel.
  • The exact expiry boundary, missing expiry, uppercase/lowercase UTC suffixes, explicit offsets, and naive UTC timestamps.

The added update/cancel regression returned 200 before the review fix; lowercase UTC and naive timestamp cases also failed before hardening.

Validation

  • Full Python server suite: 365 passed, with 22 passing subtests.
  • Ruff lint and format checks clean on all changed files.
  • Local HTTP mocks were run with proxy environment variables unset.

Existing idempotency replay behavior and reuse of an already-existing incomplete checkout are unchanged.

@google-cla

google-cla Bot commented Nov 4, 2026

Copy link
Copy Markdown

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 damaz91 added the status:needs-triage Signal that the PR is ready for human triage label Nov 4, 2026

@damaz91 damaz91 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 returns 200 OK while preserving the past existing.expires_at, so a caller gets 200 OK on update followed immediately by 404 RESOURCE_NOT_FOUND on GET /carts/{id} or checkout conversion (and POST /carts/{id}/cancel similarly returns 200 OK on an expired cart). Checking if not existing_data or is_cart_expired(existing_data): in update_cart and cancel_cart keeps all Cart endpoints consistent.
  • Optional minor hardening: In is_cart_expired, normalizing both "Z" and lowercase "z" (RFC 3339 allows both) and defaulting parsed.tzinfo is None to datetime.timezone.utc guards against a TypeError (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.
@arjun2075
arjun2075 force-pushed the fix/python-expired-cart branch from 029618f to ba20fb2 Compare November 11, 2026 00:40
@damaz91 damaz91 added status:under-review and removed status:needs-triage Signal that the PR is ready for human triage labels Nov 12, 2026

@damaz91 damaz91 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants