[Graphql] Type issue in 2.4.7
Preconditions and environment
- Magento version 2.4.7
Steps to reproduce
- 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”.
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:
@magento give me 2.4-develop instance- upcoming 2.4.x release- For more details, review the Magento Contributor Assistant documentation.
- Add a comment to assign the issue:
@magento I am working on this - To learn more about issue processing workflow, refer to the Code Contributions.
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-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: XXXXXlabel to the ticket, indicating the functional areas it may be related to. - [ ] 4. Verify that the issue is reproducible on
2.4-developbranchDetails
- Add the comment@magento give me 2.4-develop instanceto deploy test instance on Magento infrastructure.
- If the issue is reproducible on2.4-developbranch, please, add the labelReproduced 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: Confirmedonce verification is complete. - [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
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,
:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-11878 is successfully created for this GitHub issue.
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,
I guess any query that retrieve Customer object. You'll probably also need a custom attribute (dropdown) for customer entity type.
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.
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
}
}
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: XXXXXlabel to the ticket, indicating the functional areas it may be related to. - [ ] 4. Verify that the issue is reproducible on
2.4-developbranchDetails
- Add the comment@magento give me 2.4-develop instanceto deploy test instance on Magento infrastructure.
- If the issue is reproducible on2.4-developbranch, please, add the labelReproduced 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: Confirmedonce verification is complete. - [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
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:
Hence confirming this issue.
Thank you.
:x: Cannot export the issue. This GitHub issue is already linked to Jira issue(s): https://jira.corp.adobe.com/browse/AC-11878
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