Magento: Bug Found – “Invalid option ID specified …” on Export

Version Tested: Not sure if this bug exists yet in any other versions.

I was doing a product export today with Magento’s built-in export profile “Export All Products”. I noticed that there were hundreds of errors like this:

"Invalid option ID specified for region_code (59), skipping the record. (Line 134, SKU: AV71146)"

So, I checked everything I could to make sure it was setup properly: I checked the product, and a value was assigned (it’s a dropdown in my case), I checked the attribute itself to make sure that “59” was a valid option id, I checked the database to make sure nothing looked out of whack both on the product, and the option and values. Everything seemed fine.

I then decided to search the code for “skipping the record”, and I came across this file: app/code/core/Mage/Catalog/Model/Convert/Parser/Product.php. Lines 434-440 are displayed below:

if ($attribute->usesSource()) {
  $option = $attribute->getSource()->getOptionText($value);
  if ($value && empty($option)) {
    $message = Mage::helper('catalog')->__("Invalid option ID specified for %s (%s), skipping the record.", $field, $value);
    $this->addException($message, Mage_Dataflow_Model_Convert_Exception::ERROR);

I did some logging and found out that the getOptionText() method was indeed returning the proper values. The kicker is this: One of the values for this particular attribute is the number zero ‘0’. So, the second line sets $option to 0. Then, when it runs if ($value && empty($option)), it then assumes $option is actually empty because it’s 0, thus throwing the error on the export results.

The Problem: You cannot use the number 0 as an option for a dropdown or multiselect attribute option.
The Fix: Rename the option, or better yet, Magento should fix the code to allow for 0 as an option.

This entry was posted in Magento. Bookmark the permalink.

8 Responses to Magento: Bug Found – “Invalid option ID specified …” on Export

  1. taha azzabi says:

    Thanks for sharing i had the same problem

  2. I fixed my problem by filling the empty attribute in my products.
    Magento version
    Hope it helps

  3. Jim Manico says:

    The proper fix here is to change instances of:

    if ($value && empty($option)),


    if ($value && !isset($option)) {

    • Josh Pratt says:

      Jim – Which, I hope you wrote a module for and didn’t overwrite the core files.

  4. Jim Manico says:

    This same bug still seems to exist in Magento Enterprise Oh my!

  5. wlad says:

    Can anybody give a detailed “how-to fix”, please?

  6. a fix would be to use the following comparison (not tested, but i think that getOptionText will return false if nothing found, should be looked before):

    if($value && $option === false)

    • Josh Pratt says:

      But, in order to fix it the right way, you’d have to create a module to do so. Don’t want to be overwriting core files, and preferably not putting files in app/code/local/Mage/. Better to just change your option value :)