Skip to content

Error. Could not save child: "Unknown entity type: Magento\Bundle\Model\Selection\Interceptor requested" #40117

@faradey

Description

@faradey

Preconditions and environment

  • Magento version 2.4.6, 2.4.7, 2.4.8

Steps to reproduce

  1. Create a module VendorName/ModuleName.

  2. Add a plugin in the app/code/VendorName/ModuleName/etc/adminhtml/di.xml file:

<type name="Magento\Framework\DataObject">
<plugin name="VendorName\ModuleName\Plugin\MagentoFramework\Model\DataObjectPlugin"
type="VendorName\ModuleName\Plugin\MagentoFramework\Model\DataObjectPlugin"
disabled="false" sortOrder="1000"/>
</type>
  1. Create the class VendorName\ModuleName\Plugin\MagentoFramework\Model\DataObjectPlugin:
<?php
/**
* Copyright © VendorName. All rights reserved.
*/

namespace VendorName\ModuleName\Plugin\MagentoFramework\Model;

use Error;
use Exception;
use VendorName\ModuleName\Helper\DataRegistry;
use VendorName\ModuleName\Helper\ActionLog;
use Magento\Framework\App\Area;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\App\State;
use Magento\Framework\DataObject;
use Psr\Log\LoggerInterface;

class DataObjectPlugin
{
public ScopeConfigInterface $config;
public LoggerInterface $logger;
public DataRegistry $registry;
public ActionLog $actionLog;
public RequestInterface $request;
public State $state;

public function __construct(
ScopeConfigInterface $config,
LoggerInterface      $logger,
DataRegistry         $registry,
ActionLog            $actionLog,
RequestInterface     $request,
State                $state
) {
$this->config = $config;
$this->logger = $logger;
$this->registry = $registry;
$this->actionLog = $actionLog;
$this->request = $request;
$this->state = $state;
}

/**
* @param DataObject $subject
* @param $result
* @return DataObject
*/
public function afterBeforeSave(
DataObject $subject,
$result
) {
if (!($subject instanceof \Magento\Framework\Model\AbstractModel)) {
return $result;
}

try {
if ((int)$this->config->getValue(ActionLog::XML_PATH_ENABLE) == 1
&& (int)$this->config->getValue(ActionLog::XML_PATH_ENABLE_REVERT) == 1
&& $this->state->getAreaCode() == Area::AREA_ADMINHTML
&& !empty($this->request->getParams())
&& !$this->actionLog->isUnusedModel($subject)
) {
$registryData = $this->registry->getValue(ActionLog::REGISTRY_KEY_REVERT) ?? [];
if (!isset($registryData[get_class($subject)])) {
$registryData[get_class($subject)] = [];
}
$registryData[get_class($subject)][] = [
'id' => $subject->getId(),
'action_type' => $subject->getId() == null ? 'create' : 'update',
'before' => $this->actionLog->getOrigData($subject),
'status' => false,
];
$this->registry->unsValue(ActionLog::REGISTRY_KEY_REVERT);
$this->registry->setValue(ActionLog::REGISTRY_KEY_REVERT, $registryData);
}
} catch (Exception|Error $e) {
$this->logger->critical($e->getMessage());
}

return $result;
}

/**
* @param DataObject $subject
* @return void
*/
public function beforeAfterSave(
DataObject $subject
) {
if (!($subject instanceof \Magento\Framework\Model\AbstractModel)) {
return;
}

try {
if ((int)$this->config->getValue(ActionLog::XML_PATH_ENABLE) == 1
&& (int)$this->config->getValue(ActionLog::XML_PATH_ENABLE_REVERT) == 1
&& $this->state->getAreaCode() == Area::AREA_ADMINHTML
&& !empty($this->request->getParams())
&& !$this->actionLog->isUnusedModel($subject)
&& $subject->getId()
) {
$registryData = $this->registry->getValue(ActionLog::REGISTRY_KEY_REVERT) ?? [];
if (!empty($registryData[get_class($subject)])) {
foreach ($registryData[get_class($subject)] as &$registryDatum) {
if ((!empty($registryDatum['id']) && $registryDatum['id'] == $subject->getId())
|| ($subject->getId() && empty($registryDatum['id']) && $registryDatum['action_type'] == 'create')
) {
$registryDatum['id'] = $subject->getId();
$registryDatum['status'] = true;
$registryDatum['scope'] = $this->actionLog->getScope();
$registryDatum['scope_id'] = $this->actionLog->getStoreId($subject);
}
}
$this->registry->unsValue(ActionLog::REGISTRY_KEY_REVERT);
$this->registry->setValue(ActionLog::REGISTRY_KEY_REVERT, $registryData);
}
}
} catch (Exception|Error $e) {
$this->logger->critical($e->getMessage());
}
}

public function beforeBeforeDelete(
DataObject $subject
) {
if (!($subject instanceof \Magento\Framework\Model\AbstractModel)) {
return;
}

try {
if ((int)$this->config->getValue(ActionLog::XML_PATH_ENABLE) == 1
&& (int)$this->config->getValue(ActionLog::XML_PATH_ENABLE_REVERT) == 1
&& $this->state->getAreaCode() == Area::AREA_ADMINHTML
&& !empty($this->request->getParams())
&& !$this->actionLog->isUnusedModel($subject)
) {
$registryData = $this->registry->getValue(ActionLog::REGISTRY_KEY_REVERT) ?? [];
if (!isset($registryData[get_class($subject)])) {
$registryData[get_class($subject)] = [];
}
$registryData[get_class($subject)][] = [
'id' => $subject->getId(),
'status' => true,
'action_type' => 'delete',
'scope' => $this->actionLog->getScope(),
'scope_id' => $this->actionLog->getStoreId($subject),
'before' => $this->actionLog->getOrigData($subject),
];
$this->registry->unsValue(ActionLog::REGISTRY_KEY_REVERT);
$this->registry->setValue(ActionLog::REGISTRY_KEY_REVERT, $registryData);
}
} catch (Exception|Error $e) {
$this->logger->critical($e->getMessage());
}
}
}
  1. Execute bin/magento setup:upgrade.

  2. Create/update a bundle product.

Expected result

The product is saved without errors.

Actual result

When saving the product, we get the error:
Could not save child: "Unknown entity type: Magento\Bundle\Model\Selection\Interceptor requested"

Additional information

No response

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

    Area: FrameworkComponent: BundleIssue: needs updateAdditional information is require, waiting for responsePriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: PR CreatedIndicates that Pull Request has been created to fix issueReported on 2.4.8Indicates 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

    Status

    Ready for Development

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions