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

REST API multiselect attribute values are sent in an incompatible format and cannot be cleared #6120

Closed
dnadle opened this issue Aug 11, 2016 · 19 comments
Assignees
Labels
bug report Component: Catalog Component: Framework/Webapi USE ONLY for FRAMEWORK RELATED BUG! E.g If bug related to Catalog WEB API use just Catalog Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development

Comments

@dnadle
Copy link

dnadle commented Aug 11, 2016

Preconditions

  1. Magento 2.1.0

Steps to reproduce

  1. Add a product attribute with multiple select input type and define several options (values).
  2. Choose a sku set some values for the attribute.
  3. GET the sku with /V1/products/{sku}
  4. Wrap the returned JSON body with { "product": <JSON GET result> }.
  5. PUT the sku with /V1/products/{sku}
  6. Edit the JSON body and set the attribute value to [] (empty array).
  7. PUT the sku again.

Expected result

  1. The unchanged results of a GET should PUT without errors.
  2. A multi select attribute with a single option with id "123" selected should be sent as ["123"].
  3. Multiple options selected should look like ["123","456"].
  4. Putting a an empty array should clear all the selected options for the attribute.

Actual result

  1. Putting an unchanged GET returns errors on the multiselect attribute: { "message": "Error occurred during \"custom_attributes\" processing. Attribute \"occasion\" has invalid value. Invalid type for value: \"string\". Expected Type: \"string[]\"." }
  2. If the attribute has a single option, it is sent as "123", not ["123"].
  3. If the attribute has multiple options, it is sent as "123,456", not ["123","456"].
  4. Putting an empty array does not remove whatever options are selected.
@vkorotun vkorotun added Component: Catalog Component: Framework/Webapi USE ONLY for FRAMEWORK RELATED BUG! E.g If bug related to Catalog WEB API use just Catalog labels Aug 19, 2016
@sevos1984
Copy link
Contributor

After 7th step I get updated product, if I send values:[] I get "Invalid option value" message. Only 4th point of expected is reproduced and it looks like improvement.

@dnadle
Copy link
Author

dnadle commented Sep 6, 2016

I don't understand this comment. All four points of "expected" are what should happen. If any one of those points do not happen it is clearly a bug.

@dnadle
Copy link
Author

dnadle commented Sep 6, 2016

In 2.1.1, Above actual results 1 though 4 still happen. This is still a bug and the tag should not have been removed.

@pboisvert
Copy link

@mbrinton01 please review this one and confirm if bug or improvement

@piotrekkaminski
Copy link
Contributor

Thank you for your submission.

We recently made some changes to the way we process GitHub submissions to more quickly identify and respond to core code issues.

Feature Requests and Improvements should now be submitted to the new Magento 2 Feature Requests and Improvements forum (see details here).

We are closing this GitHub ticket and have moved your request to the new forum.

@dnadle
Copy link
Author

dnadle commented Sep 15, 2016

This is not a "feature request," it's a serious bug. How about letting the assignee weigh in on it before closing it?

@mbrinton01
Copy link

@dnadle, sorry for the confusion. This was picked up by an automated script. I've recreated it as a bug and we are tracking it internally as MAGETWO-58652.

@mbrinton01 mbrinton01 reopened this Sep 16, 2016
@mbrinton01 mbrinton01 added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development bug report 2.1.x and removed improvement moved_to_forums labels Sep 16, 2016
@dnadle
Copy link
Author

dnadle commented Sep 16, 2016

Thank you!

@techgeeksquared
Copy link

techgeeksquared commented Sep 29, 2016

Has there been any update on this issue, or a workaround that we could implement?

@mbrinton01
Copy link

@misha-kotov please research this issue

@mbrinton01 mbrinton01 assigned misha-kotov and unassigned mbrinton01 Jan 27, 2017
@tigerx7
Copy link

tigerx7 commented Apr 30, 2017

I can confirm that this is still an issue on 2.1.6. We've found an inconsistency in the product model retrieving the value for a multiselect, getData() returns a comma delimited value yet getAttributeText() returns an array when there's multiple values (but a single string non-array when there's only one item). This inconsistency has lead to several issues we've had to accommodate in our customizations and I'm surprised this was reported in August 2016 with no updates/fixes.

Our current workaround at the moment is to detect if the return value is a string, if so, we convert it to an array via explode(); or if empty string, set an empty array.

@misha-kotov
Copy link

Part of this fix is in progress and will be delivered to mainline soon. Namely, you'll be able to PUT the same payload that you received by doing a GET (ie, PUT will support string input). Since simply replacing string data type with arrays is a backwards incompatible change, we've decided to break it into a separate task for later and will combine with other backwards-incompatible changes in a later release where we'll likely have to version our APIs.

magento-team pushed a commit that referenced this issue May 12, 2017
…t in an incompatible format and cannot be cleared #6120
magento-team pushed a commit that referenced this issue May 12, 2017
…t in an incompatible format and cannot be cleared #6120
magento-team pushed a commit that referenced this issue May 12, 2017
…t in an incompatible format and cannot be cleared #6120
magento-team pushed a commit that referenced this issue May 12, 2017
- MAGETWO-53431 [GITHUB] SOAP API Encoding Object has no 'label' property #4630
- MAGETWO-58652 [GitHub] REST API multiselect attribute values are sent in an incompatible format and cannot be cleared #6120
- MAGETWO-62567 Make static file versioning number not based on timestamp
- MAGETWO-63741 [FT] Magento\Catalog\Test\TestCase\Product\CreateSimpleProductEntityTest fails on CI
@dnadle
Copy link
Author

dnadle commented May 13, 2017

The problem with not fixing this bug ASAP is that the only way to clear a multi-select field of all selections is to delete the product and re-create it, which breaks all links to that product in customers' order history, re-ordering, etc. I don't think you should wait until it's a convenient time from an API versioning perspective. There are other pragmatic ways to fix this bug.

Instead of waiting to version the whole API, why not just send two versions of any multi-select field and accept either version in POST? For example, send: attribute: "123,456", attribute-v2: ["123", "456"].

@veloraven
Copy link
Contributor

This issue was fixed in develop branch.
Internal ticket for ver. 2.1. - MAGETWO-67765

@Krekoss
Copy link

Krekoss commented Aug 1, 2017

@veloraven I could not find commit "MAGETWO-67765". Please provide correct name of the commit. Thank you.

@misha-kotov
Copy link

@Krekoss you should be looking for MAGETWO-58652 instead (commits into develop)

@magento-engcom-team magento-engcom-team added 2.1.x Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development bug report Component: Catalog Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Component: Framework/Webapi USE ONLY for FRAMEWORK RELATED BUG! E.g If bug related to Catalog WEB API use just Catalog labels Sep 11, 2017
@magento-engcom-team magento-engcom-team added the Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed label Oct 10, 2017
@magento-engcom-team
Copy link
Contributor

@dnadle, thank you for your report.
The issue is already fixed in develop branch, 2.2.0

@stefanfr
Copy link

stefanfr commented Dec 3, 2018

Issue still in 2.3 release
{ "message": "Error occurred during \"custom_attributes\" processing. Attribute \"ec_label\" has invalid value. The \"array\" value's type is invalid. The \"string\" type was expected. Verify and try again.", "trace": null }

@clicks-richter
Copy link

clicks-richter commented Feb 7, 2019

I have exact the same problem with multiselect attributes. Is there a fix for the problem in magento 2.3?

{"message":"Error occurred during \"customAttributes\" processing. Attribute \"base_size\" has invalid value. The \"array\" value's type is invalid. The \"string\" type was expected. Verify and try again.","trace":null}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Component: Catalog Component: Framework/Webapi USE ONLY for FRAMEWORK RELATED BUG! E.g If bug related to Catalog WEB API use just Catalog Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development
Projects
None yet
Development

No branches or pull requests