magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

[Graphql] Type issue in 2.4.7

Open Nuranto opened this issue 1 year ago • 8 comments

Preconditions and environment

  • Magento version 2.4.7

Steps to reproduce

  1. Launch a graphql query that will use GetCustomSelectedOptionAttributes

Expected result

No error

Actual result

main.ERROR: Magento\Framework\GraphQl\Query\Uid::encode(): Argument #1 ($id) must be of type string, int given, called in /var/www/html/vendor/magento/module-customer-graph-ql/Model/Customer/GetCustomSelectedOptionAttributes.php on line 58

Additional information

No response

Release note

No response

Triage and priority

  • [X] 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.
  • [ ] 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”.

Nuranto avatar Apr 25 '24 14:04 Nuranto

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


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 Apr 25 '24 14:04 m2-assistant[bot]

Hi @engcom-Delta. 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- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - 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 Apr 25 '24 14:04 m2-assistant[bot]

Hi @Nuranto,

Thank you for your reporting and collaboration.

We have tried to reproduce the issue but we couldn't find GetCustomSelectedOptionAttributes mutation available.

Can you provide us the mutation used in graphql to reproduce the issue.

Thanks,

engcom-Delta avatar Apr 29 '24 13:04 engcom-Delta

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

github-jira-sync-bot avatar Apr 29 '24 14:04 github-jira-sync-bot

Hi @Nuranto,

We have tried to reproduce the issue but we couldn't find GetCustomSelectedOptionAttributes mutation available.

Could you please provide us the mutation used in graphql to reproduce the issue.

Thanks,

engcom-Delta avatar May 10 '24 15:05 engcom-Delta

I guess any query that retrieve Customer object. You'll probably also need a custom attribute (dropdown) for customer entity type.

Nuranto avatar May 13 '24 07:05 Nuranto

Hi @Nuranto ,

We have tried to fetch customer attributes with Graphql and we are not able reproduce the error .

Please find attached the screenshot and let us know if something is missed.

Screenshot 2024-05-14 at 3 37 51 PM

engcom-Delta avatar May 14 '24 10:05 engcom-Delta

I ran into this issue with a third party module that added a customer attribute of type boolean with int backend type. Although I am not sure if this is the correct fix that covers all cases, I implemented this patch that fixes the error for us:

Fix error on GraphQL customer query due to attribute type issue. See also https://github.com/magento/magento2/issues/38662

@package magento/module-customer-graph-ql

--- magento/module-customer-graph-ql/Model/Customer/GetCustomSelectedOptionAttributes.php.orig	2024-04-03 16:20:22
+++ magento/module-customer-graph-ql/Model/Customer/GetCustomSelectedOptionAttributes.php	2024-05-21 11:52:53
@@ -54,8 +54,11 @@
             if (!in_array($option->getValue(), $selectedValues)) {
                 continue;
             }
+            // Boolean attributes can actually give an `int` result here, so we must cast to string to avoid type error
+            // when encoding.
+            $value = (string) $option->getValue();
             $result[] = [
-                'uid' => $this->uid->encode($option->getValue()),
+                'uid' => $this->uid->encode($value),
                 'value' => $option->getValue(),
                 'label' => $option->getLabel()
             ];

To help with reproduction, the attribute was added as follows:

        $eavSetup->addAttribute(
            Customer::ENTITY,
            'rewards_subscription',
            [
                'type'       => 'int',
                'label'      => 'Subscription to Points Expiring Notification',
                'input'      => 'select',
                'source'     => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean',
                'required'   => true,
                'default'    => '1',
                'sort_order' => 200,
                'system'     => false,
                'position'   => 200
            ]
        );
        $subscription = $this->eavConfig->getAttribute(Customer::ENTITY, 'rewards_subscription');
        $subscription->setData(
            'used_in_forms',
            ['adminhtml_customer']
        );

A simple query as belows triggered the error:

query AccountDashboard {
  __typename
  customer {
    email
    __typename
  }
}

hnsr avatar May 21 '24 11:05 hnsr

Hi @engcom-November. 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- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - 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 Jun 04 '24 09:06 m2-assistant[bot]

Hello @Nuranto, Thank you for the report and collaboration! @hnsr thank you for the input.

Verified this issue on 2.4-develop. Created a customer custom attribute with int type, and was able to reproduce this issue.

Please refer the screenshot below: image

Hence confirming this issue.

Thank you.

engcom-November avatar Jun 05 '24 07:06 engcom-November

:x: Cannot export the issue. This GitHub issue is already linked to Jira issue(s): https://jira.corp.adobe.com/browse/AC-11878

github-jira-sync-bot avatar Jun 05 '24 07:06 github-jira-sync-bot

I just want to mention here that the main issue is the type of the frontend attribute, I have the same issue and I found that one of the attributes has "Magento\Eav\Model\Entity\Attribute\Source\Boolean" as soruce_model but the frontend_input was "select", I have changed to "boolean" and it solved the issue

zexperto avatar Apr 02 '25 12:04 zexperto