Zend certified PHP/Magento developer

Error with name attribute while creating product programatically

I’m importing products programmatically from xslx file. My script was working on Magento 2.3.3 installed from composer, but right now on version installed from zip it fails.

While saving the product I’m getting this error:

“The “Product Name” attribute value is empty. Set the attribute and try again.”

I found that error is thrown here:

Model/Entity/Attribute/Backend/AbstractBackend.php

in method validate() I’m not sure why this is failing right now (it fails on test server too). It looks like I have to set name eav attribute, but I’m not sure why. This is my part of script for creating the product. Maybe you will spot the bug:

/** @var $product MagentoCatalogModelProduct */
    $product = $objectManager->create(Product::class);
    $product->isObjectNew(true);
    $product->setTypeId($productType)
        ->setWebsiteIds([1])
        ->setAttributeSetId(4)
        ->setName($productName)
        ->setUrlKey(slugify($urlKey))
        ->setCreatedAt(strtotime('now'))
        ->setSku($sku)
        ->setCategoryIds($categories)
        ->setPrice($lowestPrice)
        ->setWeight($data[10])
        ->setCustomAttribute('ts_dimensions_length', (isset($data['size']) && $data['size']) ? $data['size']['length'] / 10 : 0)
        ->setCustomAttribute('ts_dimensions_width', (isset($data['size']) && $data['size']) ? $data['size']['width'] / 10 : 0)
        ->setCustomAttribute('ts_dimensions_height', (isset($data['size']) && $data['size']) ? $data['size']['height'] / 10 : 0)
        ->setShortDescription($data[2])
        ->setTaxClassId(0)
        ->setDescription($data[2])
        ->setMetaTitle(trim($data[14]))
        ->setMetaKeyword($data[16])
        ->setMetaDescription($data[15])
        ->setStatus((isset($data[7]) && $data[7] == 1) ? Status::STATUS_ENABLED : Status::STATUS_DISABLED)
        ->setStockData(
            [
                'use_config_manage_stock' => 1,
                'manage_stock' => 1,
                'qty' => (int)$data[6],
                'is_in_stock' => 1, // is availible in stock
            ]
        );

    // if tier prices are set - > add them
    if (isset($data['tierPrices'])) {
        $product->setTierPrices($data['tierPrices']);
    }

    if (isset($data['color'])) {
        $attr = $product->getResource()->getAttribute('color');
        if ($attr->usesSource()) {
            $avid = $attr->getSource()->getOptionId($data['color']);
            $product->setData('color', $avid);
        }
    }

    switch ($productType) {
        case Type::TYPE_VIRTUAL:
            /**
             * 1 => 'Not Visible Individually',
             * 2 => 'Catalog',
             * 3 => 'Search',
             * 4 => 'Catalog, Search'*/
            $product->setVisibility(Visibility::VISIBILITY_NOT_VISIBLE);
            break;
        case Configurable::TYPE_CODE:
        case Type::TYPE_SIMPLE:
            $product->setVisibility(Visibility::VISIBILITY_BOTH);
            break;
    }

    if (isset($data['option'])) {
        $product->setSize($data['option']->getValue());
    }

    if (file_exists($srcImgPath)) {
        $product->addImageToMediaGallery($srcImgPath, ['image', 'small_image', 'thumbnail'], false, false);
    }
    /** @var MagentoCatalogApiProductRepositoryInterface $productRepositoryFactory */
    $productRepositoryFactory = $objectManager->create(ProductRepositoryInterface::class);
    copyAdditionalImages($product, $mediaDirectory, $data[9]);
    $productRepositoryFactory->save($product);
    return $productRepositoryFactory->get($sku)->getId();