Skip to content

fix(rest/python): reject fulfillment line_item_ids that match no line item - #278

Open
aksharprabhudesai wants to merge 3 commits into
Universal-Commerce-Protocol:mainfrom
aksharprabhudesai:fix/python-reject-unknown-line-item-ids
Open

aksharprabhudesai wants to merge 3 commits into
Universal-Commerce-Protocol:mainfrom
aksharprabhudesai:fix/python-reject-unknown-line-item-ids

Conversation

@aksharprabhudesai

@aksharprabhudesai aksharprabhudesai commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #277

Description

Fulfillment methods and groups could reference line_item_ids that 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_ids carries create: 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 with 400 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.

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

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:

  1. POST /checkout-sessions create: "omit" semantics & conformance regression (53/77 conformance tests fail):

    • In the UCP schemas, line_items[].id (line_item.json), fulfillment.methods[].line_item_ids on create (fulfillment_method.json: "ucp_request": {"create": "omit", "update": "required"}), and fulfillment.groups[].line_item_ids (fulfillment_group.json: "ucp_request": "omit") are all create: "omit" because line item IDs are assigned by the server on create (str(uuid.uuid4())).
    • Consequently, on a direct POST /checkout-sessions (without cart_id), no client-supplied line_item_ids value can match the newly generated server UUIDs. Meanwhile, the UCP conformance suite (integration_test_utils.py:create_checkout_payload and fulfillment_structure_test.py:FUL-008) sends synthetic create: "omit" placeholders ("line_item_123", ["li_1", "li_2"]) on create, expecting the server to ignore create: "omit" fields — so validating line_item_ids on direct create causes 53 conformance tests to fail with 400 INVALID_REQUEST: Unknown line item 'line_item_123'.
    • Suggested fix: On create_checkout (when not cart_id), drop/ignore client-supplied line_item_ids on methods and groups and assign all_li_ids directly (matching rest/nodejs/src/api/checkout.ts and how create_checkout already ignores client-supplied checkout.id and line_item.id), and enforce _validate_line_item_ids on update_checkout (PUT /checkout-sessions/{id}) — and optionally on create_checkout only when cart_id is used (where line_items[].id already exist from the cart). Ignoring create: "omit" line_item_ids on direct create also fixes #277's silent shipping-promotion bug (promo_2 applies consistently instead of pricing against an empty item set)!
  2. Shared IntegrationTest._create_checkout_payload helper compatibility:

    • Once create_checkout ignores create: "omit" line_item_ids, please keep IntegrationTest._create_checkout_payload unchanged (rather than stripping line_item_ids there), as other tests (including #267 in cart_test.py) reuse _create_checkout_payload to construct PUT /checkout-sessions/{id} payloads where line_item_ids is required by UnifiedCheckoutUpdateRequest.

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.

@aksharprabhudesai

Copy link
Copy Markdown
Contributor Author

Thanks for catching the create: "omit" conformance regression, @damaz91!

Updated the branch:

  • create_checkout now ignores client-supplied line_item_ids on methods and groups and assigns all_li_ids directly (verified against the conformance suite: 77 passed).
  • update_checkout still enforces _validate_line_item_ids and now checks is not None so an explicit [] isn't expanded to all line items.
  • Restored IntegrationTest._create_checkout_payload and idempotency_race_test.py as on main. (Heads-up for fix(rest/python): apply each discount code once and keep totals non-negative #267: its PUT in test_checkout_update_repeated_codes_zero_total_completes reuses _create_checkout_payload's "rose" product ID without swapping in the server-assigned line_items[].id from create, so that PUT will hit _validate_line_item_ids once both land.)

@aksharprabhudesai
aksharprabhudesai force-pushed the fix/python-reject-unknown-line-item-ids branch 2 times, most recently from 26f3082 to 53e4d85 Compare November 11, 2026 04:08
@aksharprabhudesai
aksharprabhudesai force-pushed the fix/python-reject-unknown-line-item-ids branch from 53e4d85 to 0b3dee0 Compare November 11, 2026 05:02
@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.

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!

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.

[Bug]: fulfillment line_item_ids that match no line item are accepted, and shipping promotions are silently skipped

2 participants