-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subscriber for category created not having access to data #9650
Comments
The same issue is happening with |
@carlos-r-l-rodrigues, @adrien2p – this is an interesting case. I just ran two different scenarios:
const category = await productModuleService.retrieveProductCategory(data.id);
logger.info(JSON.stringify(category, null, 2)); This consistently returns the old data of the product category.
const category = await productModuleService.retrieveProductCategory(
data.id,
{ select: ["id", "name"] }
);
logger.info(JSON.stringify(category, null, 2)); This returns the expected updated category. Any idea what might be happening here? Afaict, it cannot be related to MikroORM caching and the identity map. We don't use the former, and at this point, the identity map is flushed. Let me know if I am missing something. |
@renequez, we'll look into this. In the meantime, I recommend you use Query whenever you need to access data in your application. In your case, you would need to do something like: const query = container.resolve("query")
const { data: result } = await query.graph({
entity: "product_category",
filters: { id: data.id },
fields: ["id", "name", ...]
}) Read more here. |
@olivermrbl the behaviour described here sounds indeed weird, let me have a look tomorrow |
Hi guys, thanks for the prompt answers 🚀 I've installed the snapshot from #9688. It works as expected when using Query as @olivermrbl suggested, but if I use retrieveProductCategory there's still a weird behavior: if I don't pass a All in all, I'll start using Query whenever I need to retrieve data. Is this the recommended way, basically to avoid the retrieve functions of module services? |
@renequez, yes, I recommend using Query so you can make a habit of it. It has access to all data in the application. |
Bug report
Describe the bug
Added a subscriber on the
product-category.created
event and if I try to retrieve the new category's data withretrieveProductCategory
, the result only holds the id, with the rest of the category's data missing:System information
Medusa version (including plugins): rc 6
Node.js version: 20.17.0
Database: PostgreSQL 16.4
Operating system: Windows 11
Browser (if relevant): Edge
Steps to reproduce the behavior
npx create-medusa-app@rc
.Expected behavior
I'd expect to have the rest of the category data in the result, like title, handle, whatever field was completed in the create form and is also in the database.
Code snippets
The text was updated successfully, but these errors were encountered: