fix(rest/python): stop copying client supplied omit members, safely handle attribution, and return UCP error envelope on validation failures - #196
Open
damaz91 wants to merge 3 commits into
Conversation
damaz91
force-pushed
the
fix/python-checkout-omit-fields
branch
2 times, most recently
from
August 20, 2026 08:36
2854e83 to
6e46b55
Compare
damaz91
force-pushed
the
fix/python-checkout-omit-fields
branch
from
August 20, 2026 08:43
6e46b55 to
c508735
Compare
…andle attribution, and return UCP error envelope on validation failures 1. Omit Field Leakage & Keyword Collisions: - In checkout create: continue_url, expires_at, messages, and order were not excluded from checkout_data, allowing client values to echo in the 201 response and persist to the session database (Universal-Commerce-Protocol#190). - In cart create: continue_url, expires_at, messages, and links were not excluded from cart_data, allowing client values to echo in the response. Furthermore, passing explicit keyword arguments caused 500 TypeError when these fields were supplied in the request (Universal-Commerce-Protocol#188). 2. Currency Determination: - checkout_service was reading currency from the request via getattr(checkout_req, 'currency', None), allowing clients to override merchant currency (e.g. 'currency': 'XTS') and crashing on non-string inputs (e.g. 'currency': 123) (Universal-Commerce-Protocol#189). - cart_service was hardcoding 'USD' rather than using config.get_default_currency(). 3. Line Item ID Server Assignment: - checkout_service on direct requests was reading getattr(li, 'id', None), adopting client-supplied line item IDs and crashing on non-string IDs (123) (Universal-Commerce-Protocol#189). 4. Attribution model_dump AttributeError: - AttributionCreateRequest is a type alias (dict) in ucp-sdk, so calling source_attribution.model_dump() crashed with AttributeError on direct checkout create and cart-to-checkout conversion (Universal-Commerce-Protocol#191). 5. Request Validation Error Envelope: - RequestValidationError was unhandled, falling back to FastAPI's default flat {'detail': [...]} format instead of the compliant UCP error envelope carrying code, content, and severity (Universal-Commerce-Protocol#195). This change: - Excludes all ucp_request omit and server-managed fields from create_checkout and create_cart. - Ensures currency is determined authoritatively via config.get_default_currency(). - Ensures line item IDs on direct create are server-assigned UUIDs. - Safely dumps attribution, buyer, context, signals, and discounts via hasattr check. - Registers a RequestValidationError handler in server.py returning the UCP error envelope. - Adds regression unit tests across integration_test.py and cart_test.py. Closes Universal-Commerce-Protocol#188, Universal-Commerce-Protocol#189, Universal-Commerce-Protocol#190, Universal-Commerce-Protocol#191, Universal-Commerce-Protocol#195
damaz91
force-pushed
the
fix/python-checkout-omit-fields
branch
from
August 20, 2026 08:47
c508735 to
b70aea0
Compare
carolinerg1
approved these changes
Aug 20, 2026
17 tasks
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.
Description
The create handlers in both
checkout_serviceandcart_servicebuild response models by unpacking request data via**checkout_dataand**cart_data.continue_url,expires_at,messages, andorderwere not excluded fromcheckout_data, allowing client values to echo in the201 Createdresponse and persist to the session database (Checkout create returns client supplied continue_url, expires_at and messages #190).continue_url,expires_at,messages, andlinkswere not excluded fromcart_data, allowing client values to echo in the response. Furthermore, passing explicit keyword arguments caused 500TypeErrorwhen these fields were supplied in the request (Cart create trusts request members that cart.json marks ucp_request omit #188).checkout_servicewas readingcurrencyfrom the request viagetattr(checkout_req, 'currency', None), allowing clients to override merchant currency (e.g.,"currency": "XTS") and crashing on non-string inputs (e.g.,"currency": 123) (Checkout create takes currency from the request again, and a wrong typed member returns 500 #189).cart_servicewas hardcoding"USD"rather than usingconfig.get_default_currency().checkout_serviceon direct requests was readinggetattr(li, 'id', None), adopting client-supplied line item IDs and crashing on non-string IDs ("id": 123) (Checkout create takes currency from the request again, and a wrong typed member returns 500 #189).AttributionCreateRequestis a type alias (dict) inucp-sdk, so callingsource_attribution.model_dump()crashed withAttributeError: 'dict' object has no attribute 'model_dump'on direct checkout creation and cart-to-checkout conversion (Checkout create returns 500 when the request carries attribution #191).RequestValidationErrorwas unhandled, falling back to FastAPI's default flat{"detail": [...]}format instead of the compliant UCP error envelope carryingcode,content, andseverity(Python validation errors answer with the FastAPI detail shape instead of the UCP envelope #195).This change:
ucp_request: omitand server-managed fields fromcreate_checkoutandcreate_cart.currencyis determined authoritatively viaconfig.get_default_currency()across both checkout and cart create paths.attribution,buyer,context,signals, anddiscountsviahasattr(obj, "model_dump")check.RequestValidationErrorhandler inserver.pyreturning the standard UCP error envelope on HTTP 422.integration_test.pyandcart_test.pycovering omit member dropping, currency overriding, line item ID handling, attribution support, and validation error envelopes.Category (Required)
ucp-schematool (resolver, linter, validator). (Requires Maintainer approval)Related Issues
Closes #188
Closes #189
Closes #190
Closes #191
Closes #195
Checklist
!for breaking changes).