Repository navigation
fix(rest/python): reject fulfillment line_item_ids that match no line item - #278
Conversation
damaz91
left a comment
There was a problem hiding this comment.
Thank you @aksharprabhudesai for tackling #277 and adding clear tests!
While testing this branch against the Universal-Commerce-Protocol/conformance suite and in-flight PRs, we hit two blocking issues on the POST /checkout-sessions (create) path:
-
POST /checkout-sessionscreate: "omit"semantics &conformanceregression (53/77 conformance tests fail):- In the UCP schemas,
line_items[].id(line_item.json),fulfillment.methods[].line_item_idson create (fulfillment_method.json:"ucp_request": {"create": "omit", "update": "required"}), andfulfillment.groups[].line_item_ids(fulfillment_group.json:"ucp_request": "omit") are allcreate: "omit"because line item IDs are assigned by the server on create (str(uuid.uuid4())). - Consequently, on a direct
POST /checkout-sessions(withoutcart_id), no client-suppliedline_item_idsvalue can match the newly generated server UUIDs. Meanwhile, the UCP conformance suite (integration_test_utils.py:create_checkout_payloadandfulfillment_structure_test.py:FUL-008) sends syntheticcreate: "omit"placeholders ("line_item_123",["li_1", "li_2"]) on create, expecting the server to ignorecreate: "omit"fields — so validatingline_item_idson direct create causes 53 conformance tests to fail with400 INVALID_REQUEST: Unknown line item 'line_item_123'. - Suggested fix: On
create_checkout(whennot cart_id), drop/ignore client-suppliedline_item_idson methods and groups and assignall_li_idsdirectly (matchingrest/nodejs/src/api/checkout.tsand howcreate_checkoutalready ignores client-suppliedcheckout.idandline_item.id), and enforce_validate_line_item_idsonupdate_checkout(PUT /checkout-sessions/{id}) — and optionally oncreate_checkoutonly whencart_idis used (whereline_items[].idalready exist from the cart). Ignoringcreate: "omit"line_item_idson direct create also fixes #277's silent shipping-promotion bug (promo_2applies consistently instead of pricing against an empty item set)!
- In the UCP schemas,
-
Shared
IntegrationTest._create_checkout_payloadhelper compatibility:- Once
create_checkoutignorescreate: "omit"line_item_ids, please keepIntegrationTest._create_checkout_payloadunchanged (rather than strippingline_item_idsthere), as other tests (including #267 incart_test.py) reuse_create_checkout_payloadto constructPUT /checkout-sessions/{id}payloads whereline_item_idsis required byUnifiedCheckoutUpdateRequest.
- Once
Optional minor note: On update_checkout, getattr(m_req, "line_item_ids", None) or [...] rewrites an explicit empty list "line_item_ids": [] to all line items ([] is falsy); checking is not None avoids conflating an explicit [] (e.g. on an unselected secondary method) with an omitted field.
|
Thanks for catching the Updated the branch:
|
26f3082 to
53e4d85
Compare
53e4d85 to
0b3dee0
Compare
damaz91
left a comment
There was a problem hiding this comment.
Thank you @aksharprabhudesai for the quick turnaround and thorough update!
Ignoring client-supplied create: "omit" line_item_ids on create_checkout (assigning list(all_li_ids) on methods and groups) while enforcing _validate_line_item_ids and preserving explicit [] on update_checkout cleanly resolves both #277 and the UCP conformance regression (verified locally: full conformance suite passes, along with all server unit tests). Also appreciate the heads-up on the PUT payload in #267's new test — we will coordinate that as both PRs land.
LGTM!
Fixes #277
Description
Fulfillment methods and groups could reference
line_item_idsthat match no line item. They were skipped silently when quoting shipping, so item-based shipping promotions didn't apply and the same order could be priced two ways.On create,
line_item_idscarriescreate: omit(line item IDs are assigned by the server), so client-supplied values on methods and groups are ignored and all checkout line items are assigned directly. On update, unknown IDs are rejected with400 INVALID_REQUEST(naming the ID and listing the checkout's line items), and explicit empty lists ([]) are preserved. Added regression coverage for both paths.Thanks @sanjanar06 for the clear write-up and reproduction.