magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Field translator removed from \Magento\CatalogGraphQl\Model\Resolver\Product\ProductFieldsSelector

Open pmzandbergen opened this issue 1 year ago • 1 comments

Preconditions and environment

https://github.com/magento/magento2/commit/912743cb90ad4859b03ec648524ef99e61bb7e56#diff-fecea45cc156bda365fb84d0ac56ecf5689d01847ccb6651d4ae53d2a12e7576R58

This commit removes the field translation, used by the Product (not Products!) resolver (\Magento\CatalogGraphQl\Model\Resolver\Product). This breaks fields depending on other attributes, while they work correctly when using the Products (\Magento\CatalogGraphQl\Model\Resolver\Products) resolver.

Steps to reproduce

  1. Create an attribute depending on another attribute:
    <type name="Magento\Framework\GraphQl\Query\FieldTranslator">
        <arguments>
            <argument name="translationMap" xsi:type="array">
                <item name="aliasField" xsi:type="string">regularField</item>
            </argument>
        </arguments>
    </type>
  1. Create a product with a value for regularField.
  2. Test a query using both the Product and Products resolver for the aliasField

Expected result

Both resolvers should return the same result.

Actual result

Only the Products resolver works as expected.

Additional information

There are more GraphQL bugs regarding product resolving, for example the data could be incomplete if the product is queried as part of the CartItemInterface.

I'm trying to bundle these bugs in a MR (when I've got some spare time).

Release note

No response

Triage and priority

  • [ ] Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • [ ] Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • [X] Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • [ ] Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • [ ] Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

pmzandbergen avatar Oct 17 '24 15:10 pmzandbergen

Hi @pmzandbergen. 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.


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.

m2-assistant[bot] avatar Oct 17 '24 15:10 m2-assistant[bot]

Hello @pmzandbergen,

Thank you for the report and collaboration!

We tried to verify this on 2.4-develop, but the issue is not reproducible. Added regularField and aliasField and made it dependent, but we are getting the same response with product and products query. Here is the module used to reproduce this issue. I39277V.zip

Please let us know if we are missing anything.

Thank you.

engcom-November avatar Oct 24 '24 12:10 engcom-November

Hello @pmzandbergen,

Thank you for the report and collaboration!

We tried to verify this on 2.4-develop, but the issue is not reproducible. Added regularField and aliasField and made it dependent, but we are getting the same response with product and products query. Here is the module used to reproduce this issue. I39277V.zip

Please let us know if we are missing anything.

Thank you.

Did you include the created aliasField in the GraphQL query? If so, it will be available since the underlying collection will include this field. You could update the included test by:

  • Only query aliasField, do not query both fields
  • Do not use custom_attributesV2, as it is using a separate resolver

PS Regarding custom_attributesV2, I don't fully understand the decision for this setup. It does not support GraphQL types and it is impossible to exactly specify the required fields.

pmzandbergen avatar Oct 24 '24 12:10 pmzandbergen

A patch for this issue:

--- Model/Resolver/Product/ProductFieldsSelector.php.org	2024-10-21 09:28:29
+++ Model/Resolver/Product/ProductFieldsSelector.php	2024-10-21 09:30:10
@@ -52,8 +52,10 @@
             if ($node->name->value !== $productNodeName) {
                 continue;
             }
-                $queryFields = $this->attributesJoiner->getQueryFields($node, $info);
-                $fieldNames[] = $queryFields;
+            $queryFields = array_map(function (string $fieldName): string {
+                return $this->fieldTranslator->translate($fieldName);
+            }, $this->attributesJoiner->getQueryFields($node, $info));
+            $fieldNames[] = $queryFields;
         }
 
         return array_merge(...$fieldNames);

pmzandbergen avatar Oct 24 '24 12:10 pmzandbergen

@pmzandbergen,

When querying using both product and products, I am getting null for aliasField using di.xml provided above. Please take a look at the screenshot: Product query:

{
  products(filter: { sku: { eq:"test-prd-1" } } pageSize:100 ) {
    items {
      sku
      name
      alias_field
    }
  }
}
image

Products query:

{
  products(filter: {  } pageSize:100 ) {
    items {
      sku
      name
      alias_field
    }
  }
}
image

Can you give more insight on this.

Thank you.

engcom-November avatar Oct 25 '24 08:10 engcom-November

Hi @engcom-Hotel. 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:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
  • [ ] 3. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch
    Details- If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
  • [ ] 5. Add label Issue: Confirmed once verification is complete.
  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

m2-assistant[bot] avatar Nov 04 '24 12:11 m2-assistant[bot]

@engcom-November both queries in your example are using \Magento\CatalogGraphQl\Model\Resolver\Products. Usage of the affected resolver \Magento\CatalogGraphQl\Model\Resolver\Product can be found in the following interfaces / types:

  • ConfigurableCartItem (field configured_variant)
  • OrderItemInterface (field product)
  • WishlistItemInterface (field product)

pmzandbergen avatar Nov 04 '24 13:11 pmzandbergen

Hello @pmzandbergen,

Thanks for the further inputs!

We have tried to reproduce the issue with ConfigurableCartItem (field configured_variant) and the issue is reproducible for us.

Hence confirming the issue.

Thanks

engcom-Hotel avatar Nov 05 '24 10:11 engcom-Hotel

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-13308 is successfully created for this GitHub issue.

github-jira-sync-bot avatar Nov 05 '24 10:11 github-jira-sync-bot

:white_check_mark: Confirmed by @engcom-Hotel. Thank you for verifying the issue.
Issue Available: @engcom-Hotel, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

m2-assistant[bot] avatar Nov 05 '24 10:11 m2-assistant[bot]