Skip to content

fix(rest/python): validate selected_destination_id and refresh empty group options - #282

Open
aksharprabhudesai wants to merge 4 commits into
Universal-Commerce-Protocol:mainfrom
aksharprabhudesai:fix/python-shipping-destination-options
Open

aksharprabhudesai wants to merge 4 commits into
Universal-Commerce-Protocol:mainfrom
aksharprabhudesai:fix/python-shipping-destination-options

Conversation

@aksharprabhudesai

@aksharprabhudesai aksharprabhudesai commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #262 / #272, covering the two non-blocking notes from the #272 review.

Depends on #272 (its commit is included here until it merges; I'll rebase after).

  • Reject a shipping selected_destination_id that isn't in method.destinations with 400 INVALID_REQUEST.
  • Add db.has_any_shipping_rates so an empty quote when rates are seeded means "no options for this destination" rather than "no rates configured".
  • Refresh group.options to [] when the destination isn't served, instead of keeping the previous destination's options. A selected option is then rejected the same way as any unoffered option.
  • Only preserve existing_method.groups when groups is omitted on PUT if selected_destination_id is non-null and the selected destination is unchanged, so switching or clearing the destination re-quotes cleanly without stale option errors or fulfillment costs.

@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.

Thanks @aksharprabhudesai for spinning up this follow-up PR! Using db.has_any_shipping_rates to distinguish unseeded test fixtures (None) from unserved destinations ([]) is very clean and keeps both the unit tests and conformance suite green.

One edge case worth folding in when you rebase after #272 merges:

  • Switching or clearing selected_destination_id when PUT omits groups (services/checkout_service.py around elif existing_method and existing_method.groups:):
    • If a buyer first selects a destination-specific option (e.g., "exp-ship-us" for US) and then updates selected_destination_id to another country (e.g., CA where "exp-ship-us" is not offered, or an unserved country yielding []) via a destination-only PUT that omits groups so the server can re-quote options, update_checkout currently copies existing_method.groups — including the previous selected_option_id = "exp-ship-us". _enrich_and_recalculate then refreshes group.options and rejects the address update with 400 INVALID_REQUEST: Unknown shipping option 'exp-ship-us', even though the client did not submit selected_option_id on that update. (In ca_ok in integration_test.py, shipping_method(ca, "dest_ca", {}) sends an explicit groups: [{"id": "group_1", ...}] without selected_option_id, so that path cleared it.)
    • Similarly, if a PUT clears selected_destination_id to null while omitting groups, calculated_options stays None and the preserved existing_method.groups still adds the old option's fulfillment cost to checkout.totals while status drops to incomplete.
    • Only preserving existing_method.groups's option selection/options when selected_destination_id is non-null and unchanged (or clearing selected_option_id and options when selected_destination_id changes or is cleared and m_req.groups is omitted) would let standard 2-step address updates re-quote cleanly with 200 OK and status: "incomplete".

@aksharprabhudesai

Copy link
Copy Markdown
Contributor Author

Thanks for catching that @damaz91! Updated update_checkout so existing_method.groups is only preserved when groups is omitted and the selected destination is non-null and unchanged (including when a destination id is reused with updated address fields), with regression and control tests covering destination switches, unserved destinations, in-place destination updates, and clearing selected_destination_id to null.

@aksharprabhudesai
aksharprabhudesai marked this pull request as ready for review November 16, 2026 22:55
@damaz91 damaz91 added the status:needs-triage Signal that the PR is ready for human triage label Nov 16, 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.

Thanks @aksharprabhudesai for addressing the omitted-groups destination update cases and adding thorough regression and control tests (including destination switches, unserved destinations, reused destination IDs with updated address fields, and clearing selected_destination_id to null)!

Tiny non-blocking nit for whenever you rebase after #272 merges: in _has_fulfillment_selection, g.options is None (instead of not g.options) would mirror the new None ("not quoted") vs. [] ("no options serve destination") distinction directly, though _enrich_and_recalculate already prevents a session with options == [] and a selected_option_id from being saved.

LGTM!

@damaz91
damaz91 requested a review from carolinerg1 November 17, 2026 12:42
@carolinerg1 carolinerg1 added status:under-review and removed status:needs-triage Signal that the PR is ready for human triage labels Nov 18, 2026
@carolinerg1

Copy link
Copy Markdown

Hi @aksharprabhudesai, thank you for submitting this fix.

Could you please address the branch conflicts from merging #272 and I will merge this one as well.

@aksharprabhudesai
aksharprabhudesai force-pushed the fix/python-shipping-destination-options branch from 9e2fce2 to e40ccb9 Compare November 18, 2026 20:04
@aksharprabhudesai

Copy link
Copy Markdown
Contributor Author

Rebased onto main now that #272 is merged — conflicts are resolved. Also folded in @damaz91's nit to check g.options is None in _has_fulfillment_selection.

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.

3 participants