medusajs / medusa

Building blocks for digital commerce
https://medusajs.com
MIT License
24.64k stars 2.43k forks source link

EntityPropertyNotFoundError for 'product_medias' in handleOrderPlaced Function #5886

Closed MarNeumann closed 9 months ago

MarNeumann commented 9 months ago

Preliminary Checks

Issue Summary

Issue Description: After resolving the previous TypeScript error related to 'product_medias', I encountered a runtime error in the handleOrderPlaced function, as outlined in the MedusaJS digital product delivery recipe (https://docs.medusajs.com/recipes/digital-products#deliver-digital-products-to-the-customer). The error occurs when an order is placed, and the handleOrderPlaced function is triggered.

Error Message: The error logged is: An error occurred while processing order.placed: EntityPropertyNotFoundError: Property "product_medias" was not found in "ProductVariant". Make sure your query is correct.

Steps to Reproduce:

  1. Implement the handleOrderPlaced function based on the MedusaJS digital products recipe.
  2. Place an order to trigger the handleOrderPlaced function.

Expected Behavior: The handleOrderPlaced function should successfully access the 'product_medias' field from the 'ProductVariant' entity and process the order without errors.

Actual Behavior: Upon order placement, the function fails with an EntityPropertyNotFoundError, indicating that the 'product_medias' field does not exist in the 'ProductVariant' entity, despite attempts to extend the entity.

Investigation Findings: It appears that the extension of the ProductVariant entity to include the 'product_medias' field did not correctly modify the underlying database schema, (particularly the 'product_variant' table?).

Possible Solutions or Suggestions:

Environment:

Are you interested in working on this issue?

shahednasser commented 9 months ago

Thank you @MarNeumann for submitting these issues. I've ran through the entire recipe again and fixed all code snippet errors in PR #5897 . You can either refer to the PR for the fix or find it on the main docs once the PR is merged.

MarNeumann commented 9 months ago

Hi @shahednasser, First of all, thank you so much for your continued assistance! I updated my implementation. However, it seems that the retrieveMediasByVariant function is still missing from the documentation. Additionally, just to ensure correctness, I noticed that the isPending property is not defined in the MutationObserver[...]Result interfaces. For now, I've stuck with using isLoading.

Your help is greatly appreciated! 🌌

shahednasser commented 9 months ago

Regarding retrieveMediasByVariant, I seem to forgot to add it to the PR 😅 just opened the PR #5899 to add it.

As for isPending, which version of @tanstack/react-query are you using? Because if you install the latest, it's isPending. However, if you're using v4, it's isLoading. I've added a note about it in the same PR.

MarNeumann commented 9 months ago

Haha, now that's what i am talking about! Thank you so much.