fix(pricing): strip empty rules object from price payload#16085
fix(pricing): strip empty rules object from price payload#16085AndrianBalanescu wants to merge 1 commit into
Conversation
…ajs#16084) When editing price-list prices with an empty `rules: {}` object, normalizePrices did not delete the rules property because isPresent({}) returns false. The raw rules object was then sent to the DB, causing "column rules of relation price does not exist" error. The fix separates the concerns: hasRulesInput controls price_rules assignment, while isDefined(price.rules) controls cleanup of the raw rules property.
🦋 Changeset detectedLatest commit: 1fde958 The changes in this PR will be included in the next version bump. This PR includes changesets to release 80 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Thanks for the contribution! Initial automated review looks good. Correct, well-scoped fix for issue #16084. Splits the rules handling so cleanup of the raw rules property uses isDefined(price.rules) instead of isPresent, which correctly strips an empty rules: {} (isPresent({}) is false, isDefined({}) is true) that previously leaked to the DB and caused the 'column rules does not exist' error. Template complete, linked to a verified bug issue, integration test added, changeset included, follows conventions. No security, performance, or bug concerns found. Triggered by: new PR opened |
Summary
What — Fixes a crash when editing price-list prices that include an empty
rules: {}object.Why — When a price is submitted with
rules: {},normalizePriceschecksisPresent(price.rules)to decide whether to process rules. BecauseisPresent({})returnsfalse(empty object has zero keys), the code skips the block that deletes the rawrulesproperty. Therulesobject then remains on the entry and gets sent to the database, which throwscolumn "rules" of relation "price" does not existbecause there is norulescolumn on the price table.How — Separated the two concerns that were previously tangled in one
ifblock:hasRulesInput(isPresent) still controls whetherprice_rulesandrules_countare set.isDefined(price.rules)check handles cleanup — deleting the rawrulesproperty from the payload whenever it was explicitly provided, including the empty-object case.Testing
Added an integration test in
price-list.spec.tsthat creates a price list with a price containingrules: {}and asserts the price is created successfully withrules_count: 0and emptyprice_rules.Checklist
Fixes #16084