Skip to content

fix(rest/python): reject unoffered selected_option_id with 400 INVALID_REQUEST - #272

Merged
carolinerg1 merged 2 commits into
Universal-Commerce-Protocol:mainfrom
aksharprabhudesai:fix/python-validate-selected-option
Nov 18, 2026
Merged

carolinerg1 merged 2 commits into
Universal-Commerce-Protocol:mainfrom
aksharprabhudesai:fix/python-validate-selected-option

Conversation

@aksharprabhudesai

Copy link
Copy Markdown
Contributor

Fixes #262

Rejects a checkout fulfillment group whose selected_option_id is not in the group's offered options with 400 INVALID_REQUEST (listing the offered option IDs), and checks against offered options in _has_fulfillment_selection.

@damaz91 damaz91 added the status:needs-triage Signal that the PR is ready for human triage label Nov 1, 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 fixing #262 and adding clear regression and control coverage!

Validating group.selected_option_id against group.options in _enrich_and_recalculate (returning 400 INVALID_REQUEST with the offered option IDs) and tightening _has_fulfillment_selection cleanly prevents unoffered option IDs from silently pricing shipping at $0 and marking the session ready_for_complete, while keeping unit tests that do not seed ShippingRate rows working.

Optional, non-blocking notes for future follow-up:

  • When ShippingRate rows are seeded, calculated_options can still come back empty ([]) if selected_destination_id doesn't match any entry in method.destinations or if no shipping rate serves the destination country — leaving group.options as None and bypassing if group.selected_option_id and group.options:. Validating selected_destination_id against method.destinations (and distinguishing "no rates seeded" from "0 options available for this destination") could close that remaining corner case.
  • On line 1409, if calculated_options: group.options = calculated_options leaves previous group.options in place if a subsequent PUT switches to an unserved destination that yields [].

LGTM!

@damaz91 damaz91 added status:under-review and removed status:needs-triage Signal that the PR is ready for human triage labels Nov 11, 2026
@aksharprabhudesai

aksharprabhudesai commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the review @damaz91! I've kept this PR at the approved commit and moved the two follow-up items into #282 so this one doesn't need another review.

@carolinerg1
carolinerg1 merged commit 2d08f77 into Universal-Commerce-Protocol:main Nov 18, 2026
13 checks passed
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]: rest/python: checkout accepts a selected_option_id that was never offered

3 participants