Skip to content

fix(product-reviews): fetch product_review relation on order line items in upsert workflow#35

Open
dwene wants to merge 1 commit intomainfrom
fix/upsert-product-review-line-item-query
Open

fix(product-reviews): fetch product_review relation on order line items in upsert workflow#35
dwene wants to merge 1 commit intomainfrom
fix/upsert-product-review-line-item-query

Conversation

@dwene
Copy link
Copy Markdown
Contributor

@dwene dwene commented Mar 17, 2026

Problem

Fixes #33

When calling sdk.store.productReviews.upsert, the upsert workflow fetches the order and its line items to determine whether to create or update a review. However, the query only included items.*, which fetches shallow fields on each line item — it does not traverse the product_review link.

As a result, lineItem.product_review was always undefined, so the workflow always fell into the create path and never updated an existing review.

Fix

Add "items.product_review.*" to the useQueryGraphStep fields so Medusa's query graph traverses the link and returns the existing product review (if any) for each line item.

- fields: ["*", "shipping_address.*", "customer.*", "items.*"],
+ fields: ["*", "shipping_address.*", "customer.*", "items.*", "items.product_review.*"],

Summary by CodeRabbit

  • New Features
    • Product review data is now included in order queries, enabling access to associated product reviews alongside order information for enhanced data integration across workflows.

…ms in upsert workflow

The useQueryGraphStep was only fetching 'items.*' which does not traverse
the product_review link on each line item. As a result, lineItem.product_review
was always undefined, causing every upsert to create a new review instead of
updating the existing one.

Fixes #33
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 45ae9c2a-ea61-48ee-aec1-88c55a71c188

📥 Commits

Reviewing files that changed from the base of the PR and between cd56d4d and 1e3afd3.

📒 Files selected for processing (1)
  • plugins/product-reviews/src/workflows/upsert-product-reviews.ts

Walkthrough

The order query in the upsert-product-reviews workflow was extended to include product review fields from order items by adding "items.product_review.*" to the field set. This enables the workflow to retrieve product review data associated with each order item.

Changes

Cohort / File(s) Summary
Product Review Query Extension
plugins/product-reviews/src/workflows/upsert-product-reviews.ts
Added "items.product_review.*" to the order query field set to retrieve product review data from order items, enabling the upsert workflow to access associated product review information.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding product_review relation fetching to the upsert workflow's order query.
Linked Issues check ✅ Passed The code change directly addresses issue #33 by fetching the product_review relation on line items, enabling proper upsert logic instead of always creating new reviews.
Out of Scope Changes check ✅ Passed The single-line change only adds 'items.product_review.*' to the query fields, directly addressing the root cause identified in issue #33 without introducing unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/upsert-product-review-line-item-query
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Product Review Plugin: Unable to upsert from sdk.store.productReviews.upsert

1 participant