[FIX] purchase_request: bind name before use in onchange_product_id - #3136
Open
mav-adhoc wants to merge 1 commit into
Open
[FIX] purchase_request: bind name before use in onchange_product_id#3136mav-adhoc wants to merge 1 commit into
mav-adhoc wants to merge 1 commit into
Conversation
mav-adhoc
force-pushed
the
18.0-fix-purchase_request-onchange-unbound-name
branch
3 times, most recently
from
July 24, 2026 16:48
4a6ff3d to
96b5060
Compare
When keep_description was set, the local variable `name` was only assigned inside the `if not self.keep_description` branch, leaving it unbound. It was then read on the supplier info branch (and by the final `if name:` guard), raising UnboundLocalError as soon as the matched product.supplierinfo had no product_name (or there was no supplier info and the product had no internal reference). Always bind `name`: when keep_description is set keep the description already provided on the wizard line, otherwise fall back to the product name.
mav-adhoc
force-pushed
the
18.0-fix-purchase_request-onchange-unbound-name
branch
from
July 24, 2026 16:52
96b5060 to
ff730eb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
onchange_product_idon the make-purchase-order wizard item raisedUnboundLocalError: cannot access local variable 'name'whenkeep_descriptionwas set.namewas only assigned insideif not self.keep_description:, so whenkeep_descriptionisTrueit stayed unbound and was then read:f"[...] {p_name if p_name else name}",when the matched
product.supplierinfohad noproduct_name;if name:guard when there was no supplier info andthe product had no internal reference.
Fix
Always bind
name: keep the description already provided on the wizardline when
keep_descriptionis set, otherwise fall back to the productname. Behaviour for
keep_description = Falseis unchanged.Test
Added
test_onchange_product_id_keep_description: a product without aninternal reference plus a
product.supplierinfowith an emptyproduct_name,keep_description=True, then calls the onchange. Itraises
UnboundLocalErroron the previous code and passes with the fix.