Skip to content

attribute option label / value comparison on api POST requests #32593

Open
@cfarnleitner

Description

@cfarnleitner

Preconditions (*)

  1. Magento 2.4.2

Steps to reproduce (*)

  1. Create Dropdown type Product Attribute with values required yes. Ex: M, L, XL
  2. Reindex and flush cach
  3. POST request to /rest/all/V1/products/attributes/{attributeCode}/options
    Paylod:
    { "option": { "label": "XXL", "value": "", "sort_order": 0, "is_default": false, "store_labels": [ { "store_id": 1, "label": "XXL" } ] } }

Magento will return option ID as a response ('220' in my case).

  1. If you try to call the API again with the same data, you should get the exception message, as you did, because you're trying to create duplicate labels.

  2. But, if you try to create new label which is the same as option ID you received in the previous request, Magento returns an exception, because it compares existing option IDs for the attribute with the label that has been posted:
    Payload:
    { "option": { "label": "220", "value": "", "sort_order": 0, "is_default": false, "store_labels": [ { "store_id": 1, "label": "220" } ] } }

Instead of creating new attribute label, which would be expected behavior, Magento responds that the option already exist, which is incorrect:

{ "message": "Admin store attribute option label "%1" is already exists.", "parameters": [ "220" ], }

This is cased by comparing received option label with IDs of already existing options for that attribute, as @cfarnleitner already pointed out.

This doesn't happen from the admin UI because admin controller is using different logic than the API endpoint.

Expected result (*)

API should be working fine with 200 success code.
Note: There is no issue if added from admin UI

Actual result (*)

{ "message": "Admin store attribute option label "%1" is already exists.", "parameters": [ "220" ], }


Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

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

Metadata

Metadata

Labels

Area: APIsComponent: ApiUse with concrete module component label E.g. "Component: Api" + "Catalog"Component: Framework/ApiUSE ONLY for FRAMEWORK RELATED BUG! E.g If bug related to Catalog Service Contracts use just CatalogIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: PR in progressReported on 2.4.2Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branch

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions