Open zakdma opened 4 months ago
Hi @zakdma. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:
@magento give me 2.4-develop instance
- upcoming 2.4.x release@magento I am working on this
Join Magento Community Engineering Slack and ask your questions in #github channel. :warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting. :clock10: You can find the schedule on the Magento Community Calendar page. :telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.
Hi @engcom-Bravo. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
Area: XXXXX
label to the ticket, indicating the functional areas it may be related to.2.4-develop
branch@magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure. 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.Issue: Confirmed
once verification is complete. @magento give me 2.4-develop instance
Hi @engcom-Bravo. Thank you for your request. I'm working on Magento instance for you.
Hi @engcom-Bravo, here is your Magento Instance: https://11bfd466f8c258a1113feb50fd641584.instances-prod.magento-community.engineering Admin access: https://11bfd466f8c258a1113feb50fd641584.instances-prod.magento-community.engineering/admin_b096 Login: 0094132b Password: 5f24f247854d
Hi @zakdma,
Thanks for your reporting and collaboration.
We have verified the issue in Latest 2.4-develop instance and the issue is reproducible.Kindly refer the screenshots.
Error in Exception Logs:
GraphQL (11:11)
10: items {
11: product {
^
12: sku
{"exception":"[object] (GraphQL\\Error\\Error(code: 0): Missing key \"associatedProduct\" in Order Item value data at /usr/local/var/www/magentok/magento2/vendor/webonyx/graphql-php/src/Error/Error.php:155)
[previous exception] [object] (Magento\\Framework\\Exception\\LocalizedException(code: 0): Missing key \"associatedProduct\" in Order Item value data at /usr/local/var/www/magentok/magento2/app/code/Magento/SalesGraphQl/Model/Resolver/ProductResolver.php:46)"} []
Hence Confirming the issue.
Thanks.
:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-12332 is successfully created for this GitHub issue.
:white_check_mark: Confirmed by @engcom-Bravo. Thank you for verifying the issue.
Issue Available: @engcom-Bravo, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.
@magento I'm working on this
I guess it's a normal behavior. If you delete the product and try to get the customer's order list via GraphQl, you get the next response: As you can see, the order list is still available, you just can't get product data (obviously, because you deleted it). So, hypothetically, it's possible to add order item data to product data, and the rest of it provided as null, but I think it's redundant.
Also, this issue doesn't look like an accidental bug, this behavior was developed to throw exceptions, if an order item doesn't have associated product data (for example, in our case, when the product was deleted)
I think the exception is redundant and shouldn't be throwed. It's a nullable field, and besides the error message thrown isn't really clear to frontend / the GraphQL API user.
Simply returning null is correct. The type hint in the Order Item resolver is also wrong: https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/SalesGraphQl/Model/OrderItem/DataProvider.php#L137
/** @var ProductInterface $associatedProduct */
Should be:
/** @var ProductInterface|null $associatedProduct */
Or even better, add a private function with a correct return type.
@quterorta since I've already created a patch for this issue: Are you working on the code or do you want me to create a PR?
@pmzandbergen Hm, I agree with you. Yeah, if you have already created a patch for it, you could create PR, no problems
@magento give me 2.4-develop instance
Hi @pmzandbergen. Thank you for your request. I'm working on Magento instance for you.
Hi @pmzandbergen, here is your Magento Instance: https://11bfd466f8c258a1113feb50fd641584.instances-prod.magento-community.engineering Admin access: https://11bfd466f8c258a1113feb50fd641584.instances-prod.magento-community.engineering/admin_a69f Login: 62be90e3 Password: 2bf33469180f
Hi @zakdma Any news for this issue ?
Maybe someone has already made a patch? Because I have this problem too :(
@dimitriBouteille depends on what you want to see as a fix (nullable product, product ignoring the state and scope). Simple fix could be:
--- Model/OrderItem/DataProvider.php.org 2024-07-17 10:59:31
+++ Model/OrderItem/DataProvider.php 2024-07-17 11:01:09
@@ -10,6 +10,7 @@
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\Api\SearchCriteriaBuilder;
+use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\Data\OrderItemInterface;
use Magento\Sales\Api\OrderItemRepositoryInterface;
@@ -184,15 +185,13 @@
$orderItems
);
- $searchCriteria = $this->searchCriteriaBuilder
- ->addFilter('entity_id', $productIds, 'in')
- ->create();
- $products = $this->productRepository->getList($searchCriteria)->getItems();
- $productList = [];
- foreach ($products as $product) {
- $productList[$product->getId()] = $product;
- }
- return $productList;
+ return array_combine($productIds, array_map(function (mixed $productId): ?ProductInterface {
+ try {
+ return $this->productRepository->getById($productId);
+ } catch (NoSuchEntityException $e) {
+ return null;
+ }
+ }, $productIds));
}
/**
@dimitriBouteille note that this fix is not as efficient, since we’re (trying to) load(ing) each product independently.
Using the deferred data provider would be a more efficient solution. However the existing one also has a few bugs.
Planning to fix those and this one when I’ve got some spare time.
Preconditions and environment
Steps to reproduce
simple-deleted
simple-deleted
product to cartSales/Orders
gridgenerateCustomerToken
GraphQl mutation using previously created customer credentials https://developer.adobe.com/commerce/webapi/graphql/schema/customer/mutations/generate-token/Expected result
There is a correct response with the data requested without any error
Actual result
There is error response like this
Additional information
Check exception.log and see error like this
Release note
No response
Triage and priority