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

Inventory source item's source_code is case insensitive during insert, but case sensitive during read #38488

Open
1 of 5 tasks
bap14 opened this issue Mar 2, 2024 · 33 comments
Assignees
Labels
Area: Catalog Component: Inventory 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: dev in progress Reported on 2.4.6-p4 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch

Comments

@bap14
Copy link

bap14 commented Mar 2, 2024

Preconditions and environment

  • Magento version: 2.4.6-p4

Steps to reproduce

  1. Create at least one additional custom stock source
Source NameSource Code
Warehouse Alphawarehouse_alpha
Warehouse Bravowarehouse_bravo
  1. Create a new stock associated to the website
  2. Associate the custom sources to the new stock
  3. Utilizing the API, create an inventory source item
curl 'https://magento-opensource.test/rest/default/V1/inventory/source-items' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <auth_token>' \
--data '{
    "sourceItems": [
        {
            "sku": "24-MB01",
            "source_code": "Warehouse_Bravo",
            "quantity": 5000,
            "status": 1
        }
    ]
}
'
  1. Log in to the admin panel
  2. Navigate to the catalog products grid

Expected result

The product grid renders

Actual result

An error is displayed:

Warning: Undefined array key "Warehouse_Bravo" in /var/www/html/vendor/magento/module-inventory-catalog-admin-ui/Ui/DataProvider/Product/Listing/Modifier/QuantityPerSource.php on line 142

Additional information

This appears to be because the data in the source_code column is collated to be case insensitive (utf8mb3_general_ci). The data provider for the admin grid loads the source items for the product into an array, keyed by the source_code value. While iterating over the product's source items it looks for the key in the array; however, the source item's source_code value doesn't match the source_code for the inventory source.

image

The workaround to this is to either delete the offending records, or override the private function to force the comparison to be done in a case-insensitive manner.

Release note

Fixes an issue where using the inventory/source-items API an incorrectly cased source_code value can cause the admin grid to fail to render with error Warning: Undefined array key "<source code>"

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”.
Copy link

m2-assistant bot commented Mar 2, 2024

Hi @bap14. 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.
⚠️ 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.

@bap14
Copy link
Author

bap14 commented Mar 2, 2024

@magento give me 2.4-develop instance

Copy link

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

Copy link

@bap14
Copy link
Author

bap14 commented Mar 2, 2024

This is confirmed happening in a fresh instance:

  1. Create new stock sources: warehouse_alpha and warehouse_bravo
    image
  2. Assign sources to a new stock
    image
  3. Use inventory/source-items API to add an item to an invalidly cased source: Warehouse_Bravo
curl 'https://b568f0ff472c8c82e3c2c1205da4dd50.instances-prod.magento-community.engineering/rest/default/V1/inventory/source-items' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <auth_token>' \
--data '{
    "sourceItems": [
        {
            "sku": "24-MB01",
            "source_code": "Warehouse_Bravo",
            "quantity": 5000,
            "status": 1
        }
    ]
}
'
  1. Attempt to load catalog grid
    image

@bap14
Copy link
Author

bap14 commented Mar 2, 2024

The following patch resolves the case sensitivity issue in the erroring part of the code for the admin UI grid. It just lowercases all the array keys, and then uses strtolower to find the matching array key. It was a quick-and-dirty patch to check if it would work.
magento2-38488.patch

@engcom-Bravo engcom-Bravo self-assigned this Mar 4, 2024
Copy link

m2-assistant bot commented Mar 4, 2024

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

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

@engcom-Bravo engcom-Bravo added the Reported on 2.4.6-p4 Indicates original Magento version for the Issue report. label Mar 4, 2024
@engcom-Bravo
Copy link
Contributor

@magento give me 2.4-develop instance

Copy link

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

Copy link

@engcom-Bravo
Copy link
Contributor

Hi @bap14,

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.

Steps to reproduce

  1. Create at least one additional custom stock source
Source Name | Source Code -- | -- Warehouse Alpha | warehouse_alpha Warehouse Bravo | warehouse_bravo
  1. Create a new stock associated to the website
  2. Associate the custom sources to the new stock
  3. Utilizing the API, create an inventory source item
curl 'https://magento-opensource.test/rest/default/V1/inventory/source-items' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <auth_token>' \
--data '{
    "sourceItems": [
        {
            "sku": "24-MB01",
            "source_code": "Warehouse_Bravo",
            "quantity": 5000,
            "status": 1
        }
    ]
}
'
  1. Log in to the admin panel
  2. Navigate to the catalog products grid

Screenshot from 2024-03-04 14-52-04

Screenshot from 2024-03-04 14-51-03

Screenshot from 2024-03-04 14-53-22

We are able to view the products grid.Could you please let us know if we are missing anything.

Thanks.

@engcom-Bravo engcom-Bravo added the Issue: needs update Additional information is require, waiting for response label Mar 4, 2024
@bap14
Copy link
Author

bap14 commented Mar 4, 2024

@magento give me 2.4-develop instance

Copy link

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

Copy link

@bap14
Copy link
Author

bap14 commented Mar 4, 2024

I think you're misunderstanding what was happening. The source_code field in the API request was using a capitalized version of a stock source's code. So in your configuration you used "E" and "T" as your source codes in Magento; however, you used "Warehouse_Bravo" as the source_code in the API request.

I've recorded a short video showing the setup and issue. You'll notice I'm using values under the Code column, not the Name column in my API request.

image
magento2-38488-vid.mp4

@bap14
Copy link
Author

bap14 commented Mar 4, 2024

@engcom-Bravo So I took another look at your screenshots. The video above is still helpful, but the issue is you didn't mix the casing in your API request. So you created a source with the code warehouse_bravob and then made an API request assigning to warehouse_bravob. The error comes in when the API is used and a wrongly cased source code is used (e.g. Warehouse_BravoB).

@engcom-Bravo
Copy link
Contributor

Hi @bap14,

Thanks for your quick response.

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

Steps to reproduce

  1. Create at least one additional custom stock source
Source Name | Source Code -- | -- Warehouse Alpha | warehouse_alpha Warehouse Bravo | warehouse_bravo
  1. Create a new stock associated to the website
  2. Associate the custom sources to the new stock
  3. Utilizing the API, create an inventory source item
curl 'https://magento-opensource.test/rest/default/V1/inventory/source-items' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <auth_token>' \
--data '{
    "sourceItems": [
        {
            "sku": "24-MB01",
            "source_code": "Warehouse_Bravo",
            "quantity": 5000,
            "status": 1
        }
    ]
}
'
  1. Log in to the admin panel
  2. Navigate to the catalog products grid

Screenshot from 2024-03-05 11-56-32

Error got displayed in catalog products grid.

Hence Confirming the issue.

Thanks.

@github-jira-sync-bot
Copy link

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

Copy link

m2-assistant bot commented Mar 5, 2024

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

@andreifurrnica
Copy link

@magento give me 2.4-develop instance

Copy link

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

Copy link

@andreifurrnica
Copy link

@magento give me 2.4.6-p3 instance

Copy link

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

Copy link

Hi @andreifurrnica, unfortunately there is no ability to deploy Magento instance at the moment. Please try again later.

@heerdt
Copy link

heerdt commented Apr 2, 2024

@magento give me 2.4.6-p4 instance

Copy link

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

Copy link

Hi @heerdt, unfortunately there is no ability to deploy Magento instance at the moment. Please try again later.

@heerdt
Copy link

heerdt commented Apr 2, 2024

@magento give me 2.4-develop instance

Copy link

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

Copy link

@theuargb
Copy link

@magento I am working on this

@theuargb
Copy link

magento/inventory#3411

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Catalog Component: Inventory 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: dev in progress Reported on 2.4.6-p4 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch
Projects
Status: Dev In Progress
Development

No branches or pull requests

6 participants