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

OptionManagement.validateOption throws NoSuchEntityException for "0" option label #13083

Closed
rzinnatullin opened this issue Jan 10, 2018 · 4 comments
Labels
Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed 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 Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@rzinnatullin
Copy link

Preconditions

  1. Magento 2.1.11 (and 2.2.2 I suppose)

Steps to reproduce

  1. Create a product attribute of 'dropdown' type via admin page with one option (Admin value: 0, Default Store View value: 0)
  2. Programmatically delete the option using OptionManagement.delete method
    /**
     * @var \Magento\Eav\Api\AttributeOptionManagementInterface
     */
    private $optionManagement;
...
    $this->optionManagement->delete(\Magento\Catalog\Model\Product::ENTITY, $attributeCode, $optionId);

Expected result

  1. The option should be delete w/o any errors

Actual result

  1. NoSuchEntityException with message Attribute <somecode> does not contain option with Id <someId> is thrown

Root cause

There is validateOption method in OptionManagement.php that checks if option exists:
image

getOptionText returns "0" string as it is supposed to:
image

So the root cause is in validateOption method (see the first screenshot). In line 135 it does logical NOT operator, so "0" is casted to FALSE, thus the condition is TRUE. To fix the issue the comparison should be exact: === FALSE.

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Jan 10, 2018
@orlangur
Copy link
Contributor

Hi @rzinnatullin, thanks for comprehensive investigation!

Are you interested in preparing a pull request maybe? They are processed pretty fast nowadays, it would speed up fix availability for everyone and also it is easier to discuss concrete code snippet.

@magento-engcom-team magento-engcom-team added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Feb 15, 2018
@magento-engcom-team
Copy link
Contributor

@rzinnatullin, thank you for your report.
We've acknowledged the issue and added to our backlog.

@magento-engcom-team magento-engcom-team added the Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed label Feb 15, 2018
@sidolov
Copy link
Contributor

sidolov commented Oct 27, 2018

Hi @rzinnatullin. Thank you for your report.
The issue has been fixed in #18720 by @pmclain in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.1 release.

@sidolov sidolov added the Fixed in 2.3.x The issue has been fixed in 2.3 release line label Oct 27, 2018
gelanivishal pushed a commit to gelanivishal/magento2 that referenced this issue Oct 27, 2018
The function would incorrectly through an exception when the option text was
set to a string that would evaluate to false such as "0"

Fixes magento#13083
@magento-engcom-team
Copy link
Contributor

Hi @rzinnatullin. Thank you for your report.
The issue has been fixed in #18873 by @gelanivishal in 2.2-develop branch
Related commit(s):

The fix will be available with the upcoming 2.2.8 release.

@magento-engcom-team magento-engcom-team added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Nov 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed 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 Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests

4 participants