fix(rest/python): seed valid totals when creating a checkout - #152
Merged
damaz91 merged 1 commit intoJul 30, 2026
Conversation
The SDK now enforces the totals contains cardinality (exactly one subtotal and one total) on the response models. create_checkout constructed the checkout with an empty totals list and filled it in during recalculation, so construction validated the empty list and rejected it, returning 500 on every create. Seed a valid placeholder (one subtotal + one total) at construction so the in-progress model satisfies the constraint; _recalculate_totals overwrites it with the server-authoritative amounts immediately after. Construction stays fully validated, and the emitted wire document is unchanged. Verified against the pinned SDK build with the totals validators active: full conformance suite 69 passing / 0 failures (was 67 failures). Also green without the validators: server integration tests (16) and the happy-path client, so it is safe to land independently. Relates to Universal-Commerce-Protocol/python-sdk#57
vishkaty
force-pushed
the
fix/checkout-totals-construction-order
branch
from
July 29, 2026 15:43
049f527 to
31660aa
Compare
8 tasks
damaz91
approved these changes
Jul 30, 2026
nicholasjameshall
approved these changes
Jul 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
With the totals contains cardinality now enforced on the response models (exactly one
subtotaland onetotal), everyPOST /checkout-sessionsreturns500.create_checkoutconstructs the checkout with an emptytotalslist and fills it in during_recalculate_totals(the server is the authority for pricing). Construction runs thetotalsvalidator on that empty list and raises before recalculation:The final wire document is fully valid (exactly one subtotal and one total) - this is purely about when the check fires.
Fix
Seed a valid placeholder (
[{subtotal, 0}, {total, 0}]) at construction so the in-progress model satisfies the constraint;_recalculate_totalsoverwrites it with the server-authoritative amounts immediately after. Construction stays fully validated (nomodel_construct, so extension fields likediscountsare still coerced normally), and the emitted wire document is unchanged. Single-site change increate_checkout(the update path mutates an already-valid checkout via assignment, which is not validated).Placeholder entries are passed as dicts so pydantic coerces them to the field's own
Totaltype, avoiding a generated-class identity mismatch.Verification
Booted the reference flower-shop server and ran, with the totals validators active:
Also green without the validators (released SDK, as this repo's CI resolves it), confirming it is safe to land independently:
rest/python/server pytest): 16 passedsimple_happy_path_client.py): completedruff format --checkandruff checkclean.Relates to Universal-Commerce-Protocol/python-sdk#57 (keeps that enforcement strict while keeping the reference server green).