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.53k stars 9.31k forks source link

Missing key \"model\" in Wishlist value data #36909

Open ioweb-gr opened 1 year ago

ioweb-gr commented 1 year ago

Preconditions and environment

Steps to reproduce

  1. Create a customer
mutation {

  createCustomer(

    input: {

      firstname: "John"

      lastname: "Doe"

      email: "test1@example.com"

      password: "Test1234"

      is_subscribed: true

    }

  ) {

    customer {

      firstname

      lastname

      email

      is_subscribed

    }

  }

}
  1. Get a graphQL token

    mutation {
    generateCustomerToken(email: "test1@example.com", password: "Test1234") {
    token
    }
    }
  2. Query wishlist

query {
  wishlist {
    items {
      added_at
      description
      id

      product {
        name
        image {
          url
        }
        sku
      }
      qty
    }
    items_count
    sharing_code
  }
}

Expected result

    "data": {
        "wishlist": {
            "items": null,
            "items_count": null,
            "sharing_code": null
        }
    }

Actual result

{
    "errors": [
        {
            "debugMessage": "Missing key \"model\" in Wishlist value data",
            "message": "Internal server error",
            "category": "internal",
            "locations": [
                {
                    "line": 3,
                    "column": 5
                }
            ],
            "path": [
                "wishlist",
                "items"
            ]
        }
    ],
    "data": {
        "wishlist": {
            "items": null,
            "items_count": null,
            "sharing_code": null
        }
    }
}

Additional information

This seems to be in vendor/magento/module-wishlist-graph-ql/Model/Resolver/WishlistResolver.php:63 where it returns an empty array, but instead it expects to have a model set for each item even with an empty array.

Release note

No response

Triage and priority

m2-assistant[bot] commented 1 year ago

Hi @ioweb-gr. 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 1 year ago

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:

engcom-Bravo commented 1 year ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 1 year ago

Hi @engcom-Bravo. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 1 year ago

Hi @engcom-Bravo, here is your Magento Instance: https://fcb6c12ab32b4dfbb356a20bf9edd981.instances.magento-community.engineering Admin access: https://fcb6c12ab32b4dfbb356a20bf9edd981.instances.magento-community.engineering/admin_3e53 Login: a2710bae Password: ab32c20a954a

engcom-Bravo commented 1 year ago

Hi @ioweb-gr,

Thank you for reporting and collaboration.

Verified the issue on Magento 2.4-develop instance and the issue is not reproducible.Kindly refer the screenshots.

As per Magento devdocs The wishlist query has been deprecated. Wish list information is now provided by the customer query.

We have used customer query for wishlists.


{
  customer {
    wishlists {
      id
      name
      items_count
      items_v2 {
        items {
          id
          product {
            uid
            name
            sku
          }
        }
      }
    }
  }
}

When we have no products in wishlists we got below response

Screenshot 2023-02-23 at 2 29 55 PM

When we have products in wishlists we got below response.

Screenshot 2023-02-23 at 2 29 36 PM

Kindly recheck the behavior on Magento 2.4-develop instance and elaborate steps to reproduce if the issue is still reproducible.

Please let us know if we missed anything.

Thanks.

ioweb-gr commented 1 year ago

@engcom-Bravo however, the deprecated endpoint still exists on 2.4-develop it's not entirely removed. And the issue is reproduced perfectly fine on 2.4.5-p1 with the original endpoint.

image

Do you mean because it was deprecated it is ok if it's broken?

If that's the case then imho it should be removed entirely so that users will know it's not there any more as while it's there even as deprecated, people can use it.

So in any case this issue is still valid as in: either the endpoint should be removed, or it should be fixed. Don't you agree?

engcom-Bravo commented 1 year ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 1 year ago

Hi @engcom-Bravo. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 1 year ago

Hi @engcom-Bravo, here is your Magento Instance: https://fcb6c12ab32b4dfbb356a20bf9edd981.instances.magento-community.engineering Admin access: https://fcb6c12ab32b4dfbb356a20bf9edd981.instances.magento-community.engineering/admin_f757 Login: 584c79dd Password: bb4e45eab043

engcom-Bravo commented 1 year ago

Hi @ioweb-gr,

Thanks for your update.

Verified the issue on Magento 2.4-develop instance and the issue is not reproducible.Kindly refer the screenshots.

We have used below query

query {
  wishlist {
    items {
      added_at
      description
      id

      product {
        name
        image {
          url
        }
        sku
      }
      qty
    }
    items_count
    sharing_code
  }
}
Screenshot 2023-02-24 at 12 32 38 PM

We are not getting any error.

Kindly recheck the behavior on Magento 2.4-develop instance and elaborate steps to reproduce if the issue is still reproducible.

Thanks.

ioweb-gr commented 1 year ago

@magento give me 2.4.5-p1 instance

magento-deployment-service[bot] commented 1 year ago

Hi @ioweb-gr. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 1 year ago

Hi @ioweb-gr, here is your Magento Instance: https://b38ffd4dd119588a2d13e9dd9bbeedbc.instances.magento-community.engineering Admin access: https://b38ffd4dd119588a2d13e9dd9bbeedbc.instances.magento-community.engineering/admin_4b6c Login: c7fd2fa8 Password: cf06bb40e894

ioweb-gr commented 1 year ago

2.4.5-p1 instance has an exception image

@magento give me 2.4.5 instance

magento-deployment-service[bot] commented 1 year ago

Hi @ioweb-gr. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 1 year ago

Hi @ioweb-gr, here is your Magento Instance: https://7cafa623bd2808f1da0792c4956d36d5.instances.magento-community.engineering Admin access: https://7cafa623bd2808f1da0792c4956d36d5.instances.magento-community.engineering/admin_c14a Login: 219c2650 Password: e7770b93d40a

ioweb-gr commented 1 year ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 1 year ago

Hi @ioweb-gr. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 1 year ago

Hi @ioweb-gr, here is your Magento Instance: https://fcb6c12ab32b4dfbb356a20bf9edd981.instances.magento-community.engineering Admin access: https://fcb6c12ab32b4dfbb356a20bf9edd981.instances.magento-community.engineering/admin_b1c5 Login: bf34dfc9 Password: 36cd9192c1a2

ioweb-gr commented 1 year ago

@magento give me 2.4.5 instance

magento-deployment-service[bot] commented 1 year ago

Hi @ioweb-gr. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 1 year ago

Hi @ioweb-gr, here is your Magento Instance: https://7cafa623bd2808f1da0792c4956d36d5.instances.magento-community.engineering Admin access: https://7cafa623bd2808f1da0792c4956d36d5.instances.magento-community.engineering/admin_f7c9 Login: f9ab1081 Password: 2989cbcf4c7d

ioweb-gr commented 1 year ago

OK @engcom-Bravo I've tested it online and it seems it's not working on the automated instance

Hi @ioweb-gr, here is your Magento Instance: https://fcb6c12ab32b4dfbb356a20bf9edd981.instances.magento-community.engineering Admin access: https://fcb6c12ab32b4dfbb356a20bf9edd981.instances.magento-community.engineering/admin_b1c5 Login: bf34dfc9 Password: 36cd9192c1a2

So this was a 2.4 develop instance

I'm issuing these graphql queries in succession

1 register customer

image

mutation {

  createCustomer(

    input: {

      firstname: "John"

      lastname: "Doe"

      email: "test1@example.com"

      password: "Test1234"

      is_subscribed: true

    }

  ) {

    customer {

      firstname

      lastname

      email

      is_subscribed

    }

  }

}
{
    "data": {
        "createCustomer": {
            "customer": {
                "firstname": "John",
                "lastname": "Doe",
                "email": "test1@example.com",
                "is_subscribed": true
            }
        }
    }
}

2. Login

image

mutation {
  generateCustomerToken(email: "test1@example.com", password: "Test1234") {
    token
  }
}
{
    "data": {
        "generateCustomerToken": {
            "token": "eyJraWQiOiIxIiwiYWxnIjoiSFMyNTYifQ.eyJ1aWQiOjMsInV0eXBpZCI6MywiaWF0IjoxNjc3NTAxMTA1LCJleHAiOjE2Nzc1MDQ3MDV9.WnmsaodV62pQR--Tf-PKbgkVZsjmVA1IhmSWpX_K5ow"
        }
    }
}

3. Wishlist query using the above token

image


query {
  wishlist {
    items {
      added_at
      description
      id

      product {
        name
        image {
          url
        }
        sku
      }
      qty
    }
    items_count
    sharing_code
  }
}
{
    "errors": [
        {
            "message": "Internal server error",
            "extensions": {
                "category": "internal"
            },
            "locations": [
                {
                    "line": 3,
                    "column": 5
                }
            ],
            "path": [
                "wishlist",
                "items"
            ]
        }
    ],
    "data": {
        "wishlist": {
            "items": null,
            "items_count": null,
            "sharing_code": null
        }
    }
}

The difference must be that you registered through the website so a wishlist was automatically created maybe?

ioweb-gr commented 1 year ago

I managed to create a workaround by using a plugin

<?php
/*
 * Copyright (c) 2023. IOWEB TECHNOLOGIES
 */

namespace Ioweb\GraphQlExtend\Plugin\Model\Resolver;

use Magento\Wishlist\Model\ResourceModel\Wishlist as WishlistResourceModel;
use Magento\Wishlist\Model\WishlistFactory;
use Magento\WishlistGraphQl\Model\Resolver\WishlistResolver;

class WishlistResolverPlugin
{

    /**
     * @var WishlistFactory
     */
    private $wishlistFactory;

    /**
     * @param WishlistFactory $wishlistFactory
     */
    public function __construct(WishlistResourceModel $wishlistResource, WishlistFactory $wishlistFactory)
    {
        $this->wishlistFactory = $wishlistFactory;
    }

    public function afterResolve(WishlistResolver $subject, $result)
    {
        if(empty($result)){
            $wishlist = $this->wishlistFactory->create();
            $result['model'] = $wishlist;
        }

        return $result;
    }
}

It seems just returning an empty array is not enough in the resolver. It requires to have a model defined even if it's an empty wishlist model to return something otherwise it throws exception

engcom-Bravo commented 1 year ago

Hi @ioweb-gr,

Thanks for your update.

We have followed these steps https://github.com/magento/magento2/issues/36909#issuecomment-1446253797.Verified the issue on Magento 2.4-develop instance and the issue is not reproducible.Kindly refer the screenshots.

Screenshot 2023-02-27 at 6 22 43 PM

After creating a customer using mutation we need to login with that credentials.Kindly refer this document https://developer.adobe.com/commerce/webapi/graphql/tutorials/checkout/create-customer/

Screenshot 2023-02-27 at 7 50 08 PM Screenshot 2023-02-27 at 6 22 50 PM Screenshot 2023-02-27 at 6 22 55 PM

Kindly check after sign in with that customer.Please let us know if you are still facing any issue.

Thanks.

ioweb-gr commented 1 year ago

After creating a customer using mutation we need to login with that credentials.Kindly refer this document https://developer.adobe.com/commerce/webapi/graphql/tutorials/checkout/create-customer/

I think you miss the point.

On step 2 I wrote specifically I use this request to login.

mutation {
  generateCustomerToken(email: "test1@example.com", password: "Test1234") {
    token
  }
}

I get this token from the response

{
    "data": {
        "generateCustomerToken": {
            "token": "eyJraWQiOiIxIiwiYWxnIjoiSFMyNTYifQ.eyJ1aWQiOjMsInV0eXBpZCI6MywiaWF0IjoxNjc3NTA3OTA4LCJleHAiOjE2Nzc1MTE1MDh9.aekNr2z4zCtbbyAuORi1uN5f4X4c3HKQlcXEG72KktA"
        }
    }
}

And then in the next request

query {
  wishlist {
    items {
      added_at
      description
      id

      product {
        name
        image {
          url
        }
        sku
      }
      qty
    }
    items_count
    sharing_code
  }
}

I use the token above as bearer token and execute and receive this error.

This is all on your instance

https://fcb6c12ab32b4dfbb356a20bf9edd981.instances.magento-community.engineering/graphql

Here take a postman collection and try it again with your own new customer with a new username / password set.

It always replicates if you don't go to the website and login

Keep in mind there's no frontend to login to because we're using magento only via graphql

magento2sandbox.postman_collection.zip

{
    "errors": [
        {
            "message": "Internal server error",
            "extensions": {
                "category": "internal"
            },
            "locations": [
                {
                    "line": 3,
                    "column": 5
                }
            ],
            "path": [
                "wishlist",
                "items"
            ]
        }
    ],
    "data": {
        "wishlist": {
            "items": null,
            "items_count": null,
            "sharing_code": null
        }
    }
}
engcom-Bravo commented 1 year ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 1 year ago

Hi @engcom-Bravo. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 1 year ago

Hi @engcom-Bravo, here is your Magento Instance: https://fcb6c12ab32b4dfbb356a20bf9edd981.instances.magento-community.engineering Admin access: https://fcb6c12ab32b4dfbb356a20bf9edd981.instances.magento-community.engineering/admin_9d35 Login: c3efa371 Password: e9a4b6a036ce

engcom-Bravo commented 1 year ago

Hi @ioweb-gr,

Thanks for your update.

Verified the issue on Magento 2.4-develop instance and the issue is reproducible.Kindly refer the screenshots.

Create Customer

Screenshot 2023-02-28 at 2 59 55 PM

Generate Customer Token

Screenshot 2023-02-28 at 3 00 01 PM

Wishlist query using the above token

Screenshot 2023-02-28 at 3 00 08 PM

We are getting Internal server error.

Hence confirming this issue.

Thanks.

github-jira-sync-bot commented 1 year ago

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

m2-assistant[bot] commented 1 year ago

: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.

ioweb-gr commented 1 year ago

Thank you for verifying @engcom-Bravo :) Hopefully it will be solved. I wonder if the same issue happens on the customerCart endpoint now that you mentioned. You tested it but could you verify for me if you logged in first to your dashboard before running the customerCart query for the wishlist?

Vasudev-22 commented 1 year ago

@magento I am working on this