Skip to content

fix(pricing): strip empty rules object from price payload#16085

Open
AndrianBalanescu wants to merge 1 commit into
medusajs:developfrom
AndrianBalanescu:fix/price-list-empty-rules-16084
Open

fix(pricing): strip empty rules object from price payload#16085
AndrianBalanescu wants to merge 1 commit into
medusajs:developfrom
AndrianBalanescu:fix/price-list-empty-rules-16084

Conversation

@AndrianBalanescu

Copy link
Copy Markdown

Summary

What — Fixes a crash when editing price-list prices that include an empty rules: {} object.

Why — When a price is submitted with rules: {}, normalizePrices checks isPresent(price.rules) to decide whether to process rules. Because isPresent({}) returns false (empty object has zero keys), the code skips the block that deletes the raw rules property. The rules object then remains on the entry and gets sent to the database, which throws column "rules" of relation "price" does not exist because there is no rules column on the price table.

How — Separated the two concerns that were previously tangled in one if block:

  1. hasRulesInput (isPresent) still controls whether price_rules and rules_count are set.
  2. A new isDefined(price.rules) check handles cleanup — deleting the raw rules property from the payload whenever it was explicitly provided, including the empty-object case.

Testing

Added an integration test in price-list.spec.ts that creates a price list with a price containing rules: {} and asserts the price is created successfully with rules_count: 0 and empty price_rules.

it("should create a price list with prices that have an empty rules object", ...)

Checklist

  • I have added a changeset for this PR
  • The changes are covered by relevant tests
  • I have verified the code works as intended locally
  • I have linked the related issue(s) if applicable

Fixes #16084

…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.
@AndrianBalanescu
AndrianBalanescu requested a review from a team as a code owner July 17, 2026 00:47
@changeset-bot

changeset-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1fde958

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 80 packages
Name Type
@medusajs/pricing Patch
@medusajs/medusa Patch
@medusajs/test-utils Patch
@medusajs/loyalty-plugin Patch
@medusajs/medusa-oas-cli Patch
integration-tests-http Patch
@medusajs/analytics Patch
@medusajs/api-key Patch
@medusajs/auth Patch
@medusajs/caching Patch
@medusajs/cart Patch
@medusajs/currency Patch
@medusajs/customer Patch
@medusajs/file Patch
@medusajs/fulfillment Patch
@medusajs/index Patch
@medusajs/inventory Patch
@medusajs/link-modules Patch
@medusajs/locking Patch
@medusajs/notification Patch
@medusajs/order Patch
@medusajs/payment Patch
@medusajs/product Patch
@medusajs/promotion Patch
@medusajs/rbac Patch
@medusajs/region Patch
@medusajs/sales-channel Patch
@medusajs/settings Patch
@medusajs/stock-location Patch
@medusajs/store Patch
@medusajs/tax Patch
@medusajs/translation Patch
@medusajs/user Patch
@medusajs/workflow-engine-inmemory Patch
@medusajs/workflow-engine-redis Patch
@medusajs/draft-order Patch
@medusajs/oas-github-ci Patch
@medusajs/cache-inmemory Patch
@medusajs/cache-redis Patch
@medusajs/event-bus-local Patch
@medusajs/event-bus-redis Patch
@medusajs/analytics-local Patch
@medusajs/analytics-posthog Patch
@medusajs/auth-emailpass Patch
@medusajs/auth-github Patch
@medusajs/auth-google Patch
@medusajs/caching-redis Patch
@medusajs/file-local Patch
@medusajs/file-s3 Patch
@medusajs/fulfillment-manual Patch
@medusajs/locking-postgres Patch
@medusajs/locking-redis Patch
@medusajs/notification-local Patch
@medusajs/notification-sendgrid Patch
@medusajs/payment-stripe Patch
@medusajs/core-flows Patch
@medusajs/framework Patch
@medusajs/js-sdk Patch
@medusajs/modules-sdk Patch
@medusajs/orchestration Patch
@medusajs/query Patch
@medusajs/types Patch
@medusajs/utils Patch
@medusajs/workflows-sdk Patch
@medusajs/http-types-generator Patch
@medusajs/cli Patch
@medusajs/deps Patch
@medusajs/eslint-plugin Patch
@medusajs/telemetry Patch
@medusajs/admin-bundler Patch
@medusajs/admin-sdk Patch
@medusajs/admin-shared Patch
@medusajs/admin-vite-plugin Patch
@medusajs/dashboard Patch
@medusajs/icons Patch
@medusajs/toolbox Patch
@medusajs/ui-preset Patch
create-medusa-app Patch
medusa-dev-cli Patch
@medusajs/ui Patch

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

@medusa-os-bot

medusa-os-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

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

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]: Editing price-list prices fails with column "rules" of relation "price" does not exist(emptyrules: {}not stripped innormalizePrices)

2 participants