magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.57k stars 9.32k forks source link

GraphQl products query returns error: GetAttributeValueComposite::execute(): Argument #3 ($value) must be of type string, null given #38884

Open zakdma opened 5 months ago

zakdma commented 5 months ago

Preconditions and environment

Steps to reproduce

  1. Install vanilla Magento
  2. Create DropDown attribute with code test_ddl and options: Option 1, Option 2, Option 3 and Values Required: No
  3. Set attribute parameters
    • Use in Search: Yes
    • Use in Layered Navigation: Filterable (with results)
    • Use in Search Results Layered Navigation: Yes
    • Visible on Catalog Pages on Storefront: Yes
    • Used in Product Listing: Yes
      1. Add attribute test_ddl to default Attribute set
      2. Create new product in admin with SKU simple-null
      3. Add Price, Stock, Category. Set test_ddl to Option 1
      4. Save product
      5. Open edit product form again and change test_ddl to empty value https://prnt.sc/9BdefPLEi8M4
      6. Reindex all indexes bin/magento ind:reind Please make sure they all reindexed successfully
  4. Open any graphql client and make query
    query {
    products(
      search: "simple"
    ) {
        total_count
        items {
            name
            sku
            custom_attributesV2(filters: {is_visible_on_front: true}) {
              items {
                code
                ... on AttributeValue {
                      value
                    }
                ... on AttributeSelectedOptions {
                      selected_options {
                        value
                      }
                    }
              }
            }
        }
        aggregations{
           attribute_code
           options{
             value
           }
        }
        page_info {
            page_size
            current_page
        }
    }
    }

Expected result

There is list of products with the simple-null product in it. There is no error

Actual result

There is error in response

  "errors": [
    {
      "message": "Internal server error",
      "locations": [
        {
          "line": 12,
          "column": 13
        }
      ],
      "path": [
        "products",
        "items",
        3,
        "custom_attributesV2"
      ]
    }
  ],

Check exception.log and see error:

[2024-06-27T10:00:50.656107+00:00] main.ERROR: Magento\EavGraphQl\Model\Output\Value\GetAttributeValueComposite::execute(): Argument #3 ($value) must be of type string, null given, called in /home/zak/sites/magento/test1/public/vendor/magento/module-catalog-graph-ql/Model/Resolver/Product/ProductCustomAttributes.php on line 122

GraphQL (12:13)
11:             sku
12:             custom_attributesV2(filters: {is_visible_on_front: true}) {
                ^
13:               items {
 {"exception":"[object] (GraphQL\\Error\\Error(code: 0): Magento\\EavGraphQl\\Model\\Output\\Value\\GetAttributeValueComposite::execute(): Argument #3 ($value) must be of type string, null given, called in /home/zak/sites/magento/test1/public/vendor/magento/module-catalog-graph-ql/Model/Resolver/Product/ProductCustomAttributes.php on line 122 at /home/zak/sites/magento/test1/public/vendor/webonyx/graphql-php/src/Error/Error.php:170)
[previous exception] [object] (TypeError(code: 0): Magento\\EavGraphQl\\Model\\Output\\Value\\GetAttributeValueComposite::execute(): Argument #3 ($value) must be of type string, null given, called in /home/zak/sites/magento/test1/public/vendor/magento/module-catalog-graph-ql/Model/Resolver/Product/ProductCustomAttributes.php on line 122 at /home/zak/sites/magento/test1/public/vendor/magento/module-eav-graph-ql/Model/Output/Value/GetAttributeValueComposite.php:34)"} []

Additional information

Issue is because \Magento\EavGraphQl\Model\Output\Value\GetAttributeValueInterface::execute hase third paremeter $value of type string when null value received.

Note: Just so you know, the problem is not only with null/string. There is also a problem with any other value type other than string. For example if value is int there will be the same error. I found the same issue when I added the quote address custom attribute with int type. When setting this attribute value using setShippingAddressesOnCart and retrieving the shipping address it also failed.

Release note

No response

Triage and priority

m2-assistant[bot] commented 5 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:

m2-assistant[bot] commented 5 months ago

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:

zakdma commented 5 months ago

Just so you know, the problem is not only with null/string. There is also a problem with any other value type other than string. For example if value is int there will be the same error. I found the same issue when I added the quote address custom attribute with int type. When setting this attribute value using setShippingAddressesOnCart and retrieving the shipping address it also failed.

engcom-Delta commented 5 months ago

Hi @zakdma ,

Verified the issue on 2.4-develop and we are not able to reproduce this issue.

Steps to reproduce:-

1.Install vanilla Magento 2.Create DropDown attribute with code test_ddl and options: Option 1, Option 2, Option 3 and Values Required: No 3.Set attribute parameters Use in Search: Yes Use in Layered Navigation: Filterable (with results) Use in Search Results Layered Navigation: Yes Visible on Catalog Pages on Storefront: Yes Used in Product Listing: Yes 4.Add attribute test_ddl to default Attribute set 5.Create new product in admin with SKU simple-null 6.Add Price, Stock, Category. Set test_ddl to Option 1 7.Save product 8.Open edit product form again and change test_ddl to empty value 9.Open any graphql client and make query

created attribute

Screenshot 2024-07-01 at 5 49 44 PM

the values

Screenshot 2024-07-01 at 5 50 05 PM Screenshot 2024-07-01 at 5 50 10 PM

added to default attribute set

Screenshot 2024-07-01 at 5 51 13 PM

product created and value saved to option 1

Screenshot 2024-07-01 at 5 53 59 PM

product edited value emptied and saved

Screenshot 2024-07-01 at 5 55 06 PM

no error

Screenshot 2024-07-01 at 6 02 16 PM

Please refer the attached screenshots and let us know if we missed anything.

OvalMedia commented 5 months ago

Why am I getting this response? I did not report or comment on this.

zakdma commented 4 months ago

Hey @engcom-Delta Is far as I can see from your screenshots you are not using vanilla Magento. You Magento instance has a lot of attribute sets and maybe also other data, modules or configurations. Please use vanilla magento that can be installed like this composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition public

Also please use OpenSearch as a search engine and reindex all indexes bin/magento ind:reind before making graphql request Please make sure they all reindexed successfully.

Regards.

engcom-Delta commented 4 months ago

Hi @zakdma ,

Verified the issue on 2.4-develop and we are not able to reproduce this issue.

Preconditions:-

OpenSearch search engine configured and used by Magento

Steps to reproduce:-

1.Install vanilla Magento 2.Create DropDown attribute with code test_ddl and options: Option 1, Option 2, Option 3 and Values Required: No 3.Set attribute parameters Use in Search: Yes Use in Layered Navigation: Filterable (with results) Use in Search Results Layered Navigation: Yes Visible on Catalog Pages on Storefront: Yes Used in Product Listing: Yes 4.Add attribute test_ddl to default Attribute set 5.Create new product in admin with SKU simple-null 6.Add Price, Stock, Category. Set test_ddl to Option 1 7.Save product 8.Open edit product form again and change test_ddl to empty value 9.Reindex all indexes bin/magento indexer:reindex Please make sure they all reindexed successfully 10.Open any graphql client and make query

Created new attribute

Screenshot 2024-07-02 at 7 02 56 PM Screenshot 2024-07-02 at 7 03 03 PM Screenshot 2024-07-02 at 7 03 14 PM

added on default test attribute

Screenshot 2024-07-02 at 7 03 51 PM

Created new product

Screenshot 2024-07-02 at 7 08 59 PM

edited product

Screenshot 2024-07-02 at 7 09 34 PM

Reindex all indexes

Screenshot 2024-07-02 at 7 10 20 PM

Actual result: We are not getting internal server error

Screenshot 2024-07-02 at 7 37 06 PM

Please refer the attached screenshots and let us know if we missed anything.

zakdma commented 4 months ago

Hey @engcom-Delta Don't you see an error on your screenshot? https://prnt.sc/j2P8ngjnBGGS Your request didn't return any result because of an indexation error. https://prnt.sc/T9jaBXFsuii6 That's why you don't see error 500

mattijv commented 4 months ago

Can confirm that we've run into this exact same issue. I think it might be easiest to hit if you don't use any filters in the custom_attributesV2 query, but just try getting all the attributes.

mattijv commented 4 months ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 4 months ago

Hi @mattijv. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 4 months ago

Hi @mattijv, here is your Magento Instance: https://a9e3443cace74767d676b31ac81cd65a.instances-prod.magento-community.engineering Admin access: https://a9e3443cace74767d676b31ac81cd65a.instances-prod.magento-community.engineering/admin_333d Login: 6d5a72de Password: a8340e813218

mattijv commented 4 months ago

I was able to reproduce the issue (not the exact same steps, but it's the same underlying issue) in the dev instance provisioned above.

Steps:

  1. Add a tier price to a product (I used SKU 24-WB04).
  2. Wait for indexers to run (not sure this is necessary).
  3. Query the custom_attributesV2 field for that product.

Screenshot from 2024-07-03 11-04-47 Screenshot from 2024-07-03 11-05-36

Here's the query used for copypaste convenience:

{
  products(filter: {sku: {eq:"24-WB04"}}) {
    items {
      sku
      custom_attributesV2 {
        items {
          code
          ... on AttributeValue {
            value
          }
          ... on AttributeSelectedOptions {
            selected_options {
              value
            }
          }
        }
      }
    }
  }
}
engcom-Delta commented 4 months ago

Hi @zakdma,

Verified the issue on 2.4-develop and 2.4.7 and it is reproducible.

Hence, Confirming the issue.

Steps to reproduce:-

1.Install vanilla Magento 2.Create DropDown attribute with code test_ddl and options: Option 1, Option 2, Option 3 and Values Required: No 3.Set attribute parameters Use in Search: Yes Use in Layered Navigation: Filterable (with results) Use in Search Results Layered Navigation: Yes Visible on Catalog Pages on Storefront: Yes Used in Product Listing: Yes 4.Add attribute test_ddl to default Attribute set 5.Create new product in admin with SKU simple-null 6.Add Price, Stock, Category. Set test_ddl to Option 1 7.Save product 8.Open edit product form again and change test_ddl to empty value 9.Reindex all indexes bin/magento indexer:reindex Please make sure they all reindexed successfully 10.Open any graphql client and make query

created attribute

Screenshot 2024-07-02 at 7 02 56 PM

attribute settings

Screenshot 2024-07-02 at 7 03 03 PM Screenshot 2024-07-02 at 7 03 14 PM

attribute added to default attribute set

Screenshot 2024-07-02 at 7 03 51 PM

Created new product

Screenshot 2024-07-02 at 7 08 59 PM

edited product

Screenshot 2024-07-02 at 7 09 34 PM

reindexing

Screenshot 2024-07-03 at 2 15 35 PM

Graphql result

Screenshot 2024-07-03 at 2 03 34 PM

Exception log

Screenshot 2024-07-03 at 2 17 33 PM
github-jira-sync-bot commented 4 months ago

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

m2-assistant[bot] commented 4 months ago

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

github-jira-sync-bot commented 4 months ago

:x: You don't have permission to export this issue.

zakdma commented 4 months ago

Hey @engcom-Delta @mattijv Thank you for confirming the issue. The same problem can appear for any attribute value that is not a string. For example, I faced it for the int value, but the issue reproducing is a bit complicated. As far as I can see this resolver is implemented for product, customer and quote address attributes. There some workaround patches I created to make it working before issue fixed.

--- a/Model/Customer/Address/ExtractCustomerAddressData.php
+++ b/Model/Customer/Address/ExtractCustomerAddressData.php
@@ -162,7 +162,7 @@
                 return $this->getAttributeValue->execute(
                     AddressMetadataInterface::ENTITY_TYPE_ADDRESS,
                     $customAttribute['attribute_code'],
-                    $customAttribute['value']
+                    (string)$customAttribute['value']
                 );
             },
             $attributes
--- a/Model/Resolver/Product/ProductCustomAttributes.php
+++ b/Model/Resolver/Product/ProductCustomAttributes.php
@@ -122,7 +122,7 @@
                     return $this->getAttributeValue->execute(
                         ProductAttributeInterface::ENTITY_TYPE_CODE,
                         $customAttribute['attribute_code'],
-                        $customAttribute['value']
+                        (string)$customAttribute['value']
                     );
                 },
                 $customAttributes
--- a/Model/Cart/ExtractQuoteAddressData.php
+++ b/Model/Cart/ExtractQuoteAddressData.php
@@ -86,7 +86,7 @@
                         return $this->getAttributeValue->execute(
                             'customer_address',
                             $attribute->getAttributeCode(),
-                            $attribute->getValue()
+                            (string)$attribute->getValue()
                         );
                     },
                     $address->getCustomAttributes() ?? []
github-jira-sync-bot commented 4 months ago

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

pmzandbergen commented 1 month ago

Encountered this issue today on a shop with a lot of customizations, therefore tested (and confirmed) this issue on a vanilla 2.4-develop instance.

_PS Wondering why Magento took the approach using custom_attributesV2 anyway since it won't allow the correct usage of types in GraphQL (yay, everything a String! 🤡 )_