Repository navigation
fix(rest/python): validate selected_destination_id and refresh empty group options - #282
Conversation
9660f7e to
130c772
Compare
damaz91
left a comment
There was a problem hiding this comment.
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_idwhenPUTomitsgroups(services/checkout_service.pyaroundelif existing_method and existing_method.groups:):- If a buyer first selects a destination-specific option (e.g.,
"exp-ship-us"forUS) and then updatesselected_destination_idto another country (e.g.,CAwhere"exp-ship-us"is not offered, or an unserved country yielding[]) via a destination-onlyPUTthat omitsgroupsso the server can re-quote options,update_checkoutcurrently copiesexisting_method.groups— including the previousselected_option_id = "exp-ship-us"._enrich_and_recalculatethen refreshesgroup.optionsand rejects the address update with400 INVALID_REQUEST: Unknown shipping option 'exp-ship-us', even though the client did not submitselected_option_idon that update. (Inca_okinintegration_test.py,shipping_method(ca, "dest_ca", {})sends an explicitgroups: [{"id": "group_1", ...}]withoutselected_option_id, so that path cleared it.) - Similarly, if a
PUTclearsselected_destination_idtonullwhile omittinggroups,calculated_optionsstaysNoneand the preservedexisting_method.groupsstill adds the old option's fulfillment cost tocheckout.totalswhilestatusdrops toincomplete. - Only preserving
existing_method.groups's option selection/options whenselected_destination_idis non-null and unchanged (or clearingselected_option_idandoptionswhenselected_destination_idchanges or is cleared andm_req.groupsis omitted) would let standard 2-step address updates re-quote cleanly with200 OKandstatus: "incomplete".
- If a buyer first selects a destination-specific option (e.g.,
|
Thanks for catching that @damaz91! Updated |
damaz91
left a comment
There was a problem hiding this comment.
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!
|
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. |
9e2fce2 to
e40ccb9
Compare
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).
selected_destination_idthat isn't inmethod.destinationswith400 INVALID_REQUEST.db.has_any_shipping_ratesso an empty quote when rates are seeded means "no options for this destination" rather than "no rates configured".group.optionsto[]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.existing_method.groupswhengroupsis omitted onPUTifselected_destination_idis non-null and the selected destination is unchanged, so switching or clearing the destination re-quotes cleanly without stale option errors or fulfillment costs.