Skip to content

Cannot save sku using ResourceModel saveAttribute function #36084

Closed
@ioweb-gr

Description

@ioweb-gr

Preconditions and environment

  • 2.4.3-p1

Steps to reproduce

Create a product with SKU test1
Run the following standalone script located in pub/tools/ folder

<?php
/*
 * Copyright (c) 2022. IOWEB TECHNOLOGIES
 */

ini_set('display_errors', 1);

use Magento\Framework\App\Bootstrap;
require __DIR__ . '/../../app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);

$om = $bootstrap->getObjectManager();
$state = $om->get(Magento\Framework\App\State::class);
$state->setAreaCode('adminhtml');

$productResource = $om->get(\Magento\Catalog\Model\ResourceModel\Product::class);
$productRepository = $om->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
$product = $productRepository->get('test1');
$product->setSku('test');
$productResource->saveAttribute($product, 'sku');

You will get an exception

Fatal error: Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'catalog_product_entity.value_id' in 'field list' in /var/www/vhosts/website/httpdocs/vendor/magento/framework/DB/Statement/Pdo/Mysql.php:91 Stack trace: #0 /var/www/vhosts/website/httpdocs/vendor/magento/framework/DB/Statement/Pdo/Mysql.php(91): PDOStatement->execute(Array) #1 /var/www/vhosts/website/httpdocs/vendor/magento/framework/DB/Statement/Pdo/Mysql.php(107): Magento\Framework\DB\Statement\Pdo\Mysql->Magento\Framework\DB\Statement\Pdo\{closure}() #2 /var/www/vhosts/website/httpdocs/vendor/magento/framework/DB/Statement/Pdo/Mysql.php(92): Magento\Framework\DB\Statement\Pdo\Mysql->tryExecute(Object(Closure)) #3 /var/www/vhosts/website/httpdocs/vendor/magento/zendframework1/library/Zend/Db/Statement.php(303): Magento\Framework\DB\Statement\Pdo\Mysql->_execute(Array) #4 /var/www/vhosts/website/httpdocs/vendor/magento/zendframework1/li in /var/www/vhosts/website/httpdocs/vendor/magento/framework/DB/Statement/Pdo/Mysql.php on line 110

Expected result

The sku is saved properly

Actual result

An exception is thrown


Fatal error: Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'catalog_product_entity.value_id' in 'field list' in /var/www/vhosts/website/httpdocs/vendor/magento/framework/DB/Statement/Pdo/Mysql.php:91 Stack trace: #0 /var/www/vhosts/website/httpdocs/vendor/magento/framework/DB/Statement/Pdo/Mysql.php(91): PDOStatement->execute(Array) #1 /var/www/vhosts/website/httpdocs/vendor/magento/framework/DB/Statement/Pdo/Mysql.php(107): Magento\Framework\DB\Statement\Pdo\Mysql->Magento\Framework\DB\Statement\Pdo\{closure}() #2 /var/www/vhosts/website/httpdocs/vendor/magento/framework/DB/Statement/Pdo/Mysql.php(92): Magento\Framework\DB\Statement\Pdo\Mysql->tryExecute(Object(Closure)) #3 /var/www/vhosts/website/httpdocs/vendor/magento/zendframework1/library/Zend/Db/Statement.php(303): Magento\Framework\DB\Statement\Pdo\Mysql->_execute(Array) #4 /var/www/vhosts/website/httpdocs/vendor/magento/zendframework1/li in /var/www/vhosts/website/httpdocs/vendor/magento/framework/DB/Statement/Pdo/Mysql.php on line 110

Additional information

I'm in the process of creating an automation for generating product SKUs based on a series and I was tyring to create a cron job that will automatically alter the SKUs to the appropriate format.
However this issue occured and I'm now unable to do it in a fast way and I have to use the ProductRepository to save the whole product instead of just modifying the attribute itself.

That means one extra load for the product and one extra save for the whole product instead of just saving my requested attribute

In my opinion saveAttribute should be able to save the sku as well but it seems it only works for non-static attributes.

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue: ready for confirmationReported on 2.4.3-p1Indicates original Magento version for the Issue report.Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions