Magento2: Attribute option value uniqueness is not checked if created via REST Api

Created on 10 Mar 2017  路  8Comments  路  Source: magento/magento2


Preconditions


  1. Magento CE 2.1.4
  2. PHP 7.x
  3. MySQL 5.7

Steps to reproduce

  1. Send the same call to create an option twice
    URL: /rest/V1/products/attributes/color/options
    POST:
{
    "option": {
      "label": "Black1",
      "sort_order": 9999,
      "is_default": false
    }
}
  1. Get the attribute via API or check the backend
    Response:
[
  {
    "label": "offwhite/schwarz gestreift",
    "value": "281"
  },
  {
    "label": "red1",
    "value": "286"
  },
  {
    "label": "schwarz/mehrfarbig",
    "value": "282"
  },
  {
    "label": "Black1",
    "value": "287"
  },
  {
    "label": "Black1",
    "value": "288"
  },
  {
    "label": "Black1",
    "value": "289"
  }
]

Expected result

  1. Only one option value is created
  2. Second call must fail with exception

Actual result

  1. Option values are created more than once.

FrameworWebapi Fixed in 2.2.x Fixed in 2.3.x Clear Description Confirmed Format is valid Ready for Work Reproduced on 2.1.x Reproduced on 2.2.x Reproduced on 2.3.x bug report

Most helpful comment

@hilrob Thanks for reporting this issue. Created internal issue MAGETWO-70441 to investigate and track this issue.

All 8 comments

@hilrob Thanks for reporting this issue. Created internal issue MAGETWO-70441 to investigate and track this issue.

@hilrob, thank you for your report.
We've created internal ticket(s) MAGETWO-70441 to track progress on the issue.

Working on that :)

Hi @gomencal please, accept the invite

Hi! Accepted :)

Hi @hilrob. Thank you for your report.
The issue has been fixed in magento-engcom/magento2ce#1286 by @magento-engcom-team in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming patch release.

Hi! I can see here that it is fixed at 2.3.x. But should it duplicate as well if I make a PUT request to

V1/products/attributes/{attribute_code}

Where I have the options listened on the request. For example, if I have an attribute with an option that has the label "Option Label" and makes the put request with the following options inside the attribute Json request:

{ "options": [ { "label": "Option Label" } ] }

I get these options inside the attribute.

"options": [ { "label": " ", "value": "" }, { "label": "Option Label", "value": "82" }, { "label": "Option Label", "value": "83" } ],

With the duplicated label.
Is it the right behave?
Should I forget updating the options on the attribute request and instead do it on

/rest/V1/products/attributes/{attribute_code}/options

Thanks a lot!

We experience this bug with version 2.3.5-p1

Was this page helpful?
0 / 5 - 0 ratings