Skip to content

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

Closed
@rzinnatullin

Description

@rzinnatullin

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions