Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OptionValueProvider class get() method contains an incorrect query value #35910

Closed
1 of 5 tasks
LukasDeRuiter opened this issue Aug 10, 2022 · 12 comments · Fixed by #36099
Closed
1 of 5 tasks

OptionValueProvider class get() method contains an incorrect query value #35910

LukasDeRuiter opened this issue Aug 10, 2022 · 12 comments · Fixed by #36099
Labels
Area: Framework Component: DB Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: done Reported on 2.4.3 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it

Comments

@LukasDeRuiter
Copy link

LukasDeRuiter commented Aug 10, 2022

Preconditions and environment

  • Magento version: 2.4.3

Steps to reproduce

  1. Install Adobe Commerce with sample data.

  2. Remove the following line in the DB (DELETE FROM eav_attribute_option_value WHERE eav_attribute_option_value.value_id = 221):
    2022-09-07_06-28

Try to create a return using the RequestReturnMutation GraphQL mutation with "Reason: Wrong Color".

mutation {
  requestReturn(
    input: {
      order_uid: "Mg=="
      contact_email: "john@example.com"
      comment_text: "I want to return the shirt because I don't like the texture of the fabric"
      items: { 
        order_item_uid: "NQ=="
        quantity_to_return: 1
				selected_custom_attributes: [
          {
            attribute_code: "resolution"
            value: "MjE1"
          }
          {
            attribute_code: "condition"
            value: "MjE5"
          }
          {
            attribute_code: "reason"
            value: "MjIx"
          }
        ]
        
      }
    }
  ) {
    return {
      uid
      items {
        uid
        status
        request_quantity
        quantity
        order_item {
          id
          eligible_for_return
          product_sku
          product_sku
          product_type
          quantity_returned
          status
        }
      }
      number
      status
      comments {
        uid
        author_name
        text
        created_at
      }
      customer {
        firstname
        lastname
        email
      }
    }
  }
}

What happens

GraphQL returns an error due to Magento\RmaGraphQl\Model\Rma\Item::Builder calling the method with an option_id value (if ($this->optionValueProvider->get((int)$attributeValue)) {).

The error is:

{
  "operationName": "RequestReturnMutation",
  "variables": {
    "input": {
      "contact_email": "john@example.com",
      "order_uid": "NA==",
      "items": [
        {
          "order_item_uid": "NQ==",
          "quantity_to_return": 1,
          "selected_custom_attributes": [
            {
              "attribute_code": "resolution",
              "value": "MjE1"
            },
            {
              "attribute_code": "condition",
              "value": "MjE5"
            },
            {
              "attribute_code": "reason",
              "value": "MjIx"
            }
          ]
        }
      ]
    }
  },
  "data": [
    {
      "message": "Value of reason is incorrect",
      "extensions": {
        "category": "graphql-input"
      },
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "requestReturn"
      ]
    }
  ]
}

Expected result

This method should return an attribute option value based on the given option_id.

Actual result

This method returns only an error, as the 'value_id' column is not present.

Additional information

This issue can be fixed by changing the the first parameter name to '$optionId', and changing the first parameter of the ->where method to 'option_id'. Code as example:

private function get(int $optionId): ?string
{
$select = $this->connection->select()
->from($this->connection->getTableName('eav_attribute_option_value'), 'value')
->where('option_id = ?', $optionId);

    $result = $this->connection->fetchOne($select);

    if ($result) {
        return $result;
    }

    return null;
}

Kind regards,
Lukas de Ruiter
Youwe B.V.

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.
  • 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”.
@m2-assistant
Copy link

m2-assistant bot commented Aug 10, 2022

Hi @LukasDeRuiter. Thank you for your report.
To speed up processing of this issue, make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

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.


⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

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

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@m2-community-project m2-community-project bot added this to Ready for Confirmation in Issue Confirmation and Triage Board Aug 10, 2022
@engcom-Lima engcom-Lima added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label Aug 18, 2022
@engcom-Hotel engcom-Hotel self-assigned this Aug 18, 2022
@m2-assistant
Copy link

m2-assistant bot commented Aug 18, 2022

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

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components 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.

@engcom-Hotel
Copy link
Contributor

Hello @LukasDeRuiter,

Thanks for the report and collaboration!

We have tried to reproduce the issue in Magento 2.4-develop branch but were unable to do so. We can see the value_id column in eav_attribute_option_value table. Please refer the below screenshot for reference:

image

Let us know in case we have missed anything.

Thanks

@engcom-Hotel engcom-Hotel added Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: needs update Additional information is require, waiting for response labels Aug 18, 2022
@m2-community-project m2-community-project bot moved this from Ready for Confirmation to Needs Update in Issue Confirmation and Triage Board Aug 18, 2022
@m2-community-project m2-community-project bot removed Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: ready for confirmation labels Aug 18, 2022
@engcom-Hotel
Copy link
Contributor

Dear @LukasDeRuiter,

We have noticed that this issue has not been updated for a period of 14 Days. Hence we assume that this issue is fixed now, so we are closing it. Please raise a fresh ticket or reopen this ticket if you need more assistance on this.

Regards

@real34
Copy link
Member

real34 commented Sep 7, 2022

Hi,

I can confirm @LukasDeRuiter's report.
While there are both columns, the docblock explicitely states

Get EAV attribute option value by option id

It lies!
2022-09-07_06-31

Problem

I struggled to understand why this class was introduced in the core and commits aren't helpufl in that sense.

Moreover, there is no usage of this class in Magento OpenSource (on 2.4-develop):

$ git rev-parse --short HEAD
26057964cdb
$ rg -i "OptionValueProvider" 
app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/OptionValueProvider.php
17:class OptionValueProvider

It however is used in Adobe Commerce, by the RMA GraphQL module:

$ rg -i "OptionValueProvider" vendor/magento 
vendor/magento/module-eav/Model/ResourceModel/Entity/Attribute/OptionValueProvider.php
18:class OptionValueProvider

vendor/magento/module-rma-graph-ql/Model/Rma/Item/Builder.php
14:use Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionValueProvider;
50:     * @var OptionValueProvider
52:    private $optionValueProvider;
59:     * @param OptionValueProvider $optionValueProvider
66:        OptionValueProvider $optionValueProvider
72:        $this->optionValueProvider = $optionValueProvider;
156:            if ($this->optionValueProvider->get((int)$attributeValue)) {

vendor/magento/module-rma-graph-ql/Model/Formatter/CustomAttribute.php
12:use Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionValueProvider;
32:     * @var OptionValueProvider
34:    private $optionValueProvider;
39:     * @param OptionValueProvider $optionValueProvider
44:        OptionValueProvider $optionValueProvider
48:        $this->optionValueProvider = $optionValueProvider;
61:            $value = $this->optionValueProvider->get((int)$value);

As a consequence, the RMA GraphQL module doesn't work.

To reproduce

Install Adobe Commerce with sample data.

Remove the following line in the DB (DELETE FROM eav_attribute_option_value WHERE eav_attribute_option_value.value_id = 221):
2022-09-07_06-28

Try to create a return using the RequestReturnMutation GraphQL mutation with "Reason: Wrong Color".

What happens

GraphQL returns an error due to Magento\RmaGraphQl\Model\Rma\Item::Builder calling the method with an option_id value (if ($this->optionValueProvider->get((int)$attributeValue)) {).

The error is:

{
  "operationName": "RequestReturnMutation",
  "variables": {
    "input": {
      "contact_email": "john@example.com",
      "order_uid": "NA==",
      "items": [
        {
          "order_item_uid": "NQ==",
          "quantity_to_return": 1,
          "selected_custom_attributes": [
            {
              "attribute_code": "resolution",
              "value": "MjE1"
            },
            {
              "attribute_code": "condition",
              "value": "MjE5"
            },
            {
              "attribute_code": "reason",
              "value": "MjIx"
            }
          ]
        }
      ]
    }
  },
  "data": [
    {
      "message": "Value of reason is incorrect",
      "extensions": {
        "category": "graphql-input"
      },
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "requestReturn"
      ]
    }
  ]
}

Expected

It should accept the return request and save it.

Next

I'll submit a PR to change this value, and see if no regression is detected by the Magento OpenSource test suite.
Could you please reopen this issue?

@engcom-Hotel
Copy link
Contributor

Hello @real34,

Thanks for the contribution!

We are reopening this issue for further processing.

We have a query here, in your comment you have mentioned the mutation RequestReturnMutation but instead, we have found this mutation requestReturn here in the document. Are you talking about the same?

And also can you please tell us your mutation query?

Thanks

@engcom-Hotel engcom-Hotel reopened this Sep 8, 2022
@m2-community-project m2-community-project bot removed the Issue: needs update Additional information is require, waiting for response label Sep 8, 2022
@m2-community-project m2-community-project bot added this to Ready for Confirmation in Issue Confirmation and Triage Board Sep 8, 2022
@engcom-Hotel engcom-Hotel added the Issue: needs update Additional information is require, waiting for response label Sep 8, 2022
@m2-community-project m2-community-project bot moved this from Ready for Confirmation to Needs Update in Issue Confirmation and Triage Board Sep 8, 2022
@real34
Copy link
Member

real34 commented Sep 8, 2022

Hi @engcom-Hotel,
Thanks for reopening.

It indeed is requestReturn.
Here is the code of our mutation:

mutation RequestReturnMutation($input: RequestReturnInput!) {
  requestReturn(input: $input) {
    return {
      order {
        id
      }
    }
  }
}

@engcom-Hotel
Copy link
Contributor

Hello @real34,

Thanks for the response!

Based on your comment, we have tried to reproduce the issue in Magento 2.4-develop branch. And the issue is reproducible for us. It seems that there is a mismatch in comment vs functionality. In the comment, it is written that the getting EAV attribute option value by option id but actually it is getting by value_id in the get method of app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/OptionValueProvider.php.

Hence confirming the issue and updating the description.

Thanks

@engcom-Hotel engcom-Hotel added Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Component: DB Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch labels Sep 14, 2022
@engcom-November
Copy link

Hi @LukasDeRuiter ,
Development team is currently working on this issue.
Thank you.

@github-jira-sync-bot github-jira-sync-bot added Progress: PR Created Indicates that Pull Request has been created to fix issue Progress: dev in progress and removed Progress: dev in progress labels Mar 30, 2023
@m2-community-project m2-community-project bot removed Progress: PR Created Indicates that Pull Request has been created to fix issue Progress: PR in progress labels Apr 5, 2023
@github-jira-sync-bot github-jira-sync-bot added Progress: PR Created Indicates that Pull Request has been created to fix issue and removed Progress: dev in progress labels Apr 5, 2023
@m2-community-project m2-community-project bot removed the Progress: PR Created Indicates that Pull Request has been created to fix issue label Apr 13, 2023
@github-jira-sync-bot github-jira-sync-bot added Progress: PR Created Indicates that Pull Request has been created to fix issue and removed Progress: dev in progress labels Apr 13, 2023
@m2-community-project m2-community-project bot moved this from Dev In Progress to Done in High Priority Backlog May 9, 2023
@m2-community-project m2-community-project bot added Progress: done and removed Progress: PR Created Indicates that Pull Request has been created to fix issue labels May 9, 2023
@engcom-Bravo
Copy link
Contributor

Hello,

As I can see this issue got fixed in the scope of the internal Jira ticket AC-6680 by the internal team
Related commits:https://github.com/search?q=repo%3Amagento%2Fmagento2+AC-6680&type=commits

Based on the Jira ticket, the target version is 2.4.7-beta1.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Framework Component: DB Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: done Reported on 2.4.3 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
7 participants