initializeObject() throws exception for non-managed objects with native lazy objects #7555

Open
opened 2026-01-22 15:53:23 +01:00 by admin · 0 comments
Owner

Originally created by @SherinBloemendaal on GitHub (Sep 19, 2025).

Bug Report

Q A
Version 3.5.x
Previous Version if the bug is a regression N/A (new feature bug)

Summary

When isNativeLazyObjectsEnabled() is true, calling EntityManager::initializeObject() or UnitOfWork::initializeObject() with a non-managed object throws an exception instead of performing a no-op as specified by the ObjectManager interface contract.

Current behavior

Calling initializeObject() on objects that are not Doctrine entities results in an exception:

The class 'App\Dto\TestDto' was not found in the chain configured namespaces App\Entity

This breaks the documented interface contract which states the method should be "a no-op for other objects."

Expected behavior

According to the ObjectManager interface documentation:

b0bb31ae05/src/Persistence/ObjectManager.php (L114-L119)

The method should silently do nothing when called with non-Doctrine entities, not throw an exception.

How to reproduce

<?php
use Doctrine\ORM\ORMSetup;
use Doctrine\ORM\EntityManager;

$config = ORMSetup::createAttributeMetadataConfiguration([__DIR__ . '/src'], true);
$config->enableNativeLazyObjects(true);
$entityManager = EntityManager::create($connectionParams, $config);

$nonEntity = new stdClass();
$nonEntity->someProperty = 'test';

$entityManager->initializeObject($nonEntity);
// Exception: The class 'stdClass' was not found in the chain configured namespaces
Originally created by @SherinBloemendaal on GitHub (Sep 19, 2025). ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |-------------------------------------------- | ------ | Version | 3.5.x | Previous Version if the bug is a regression | N/A (new feature bug) #### Summary When `isNativeLazyObjectsEnabled()` is `true`, calling `EntityManager::initializeObject()` or `UnitOfWork::initializeObject()` with a non-managed object throws an exception instead of performing a no-op as specified by the `ObjectManager` interface contract. #### Current behavior Calling `initializeObject()` on objects that are not Doctrine entities results in an exception: ``` The class 'App\Dto\TestDto' was not found in the chain configured namespaces App\Entity ``` This breaks the documented interface contract which states the method should be "a no-op for other objects." #### Expected behavior According to the `ObjectManager` interface documentation: https://github.com/doctrine/persistence/blob/b0bb31ae055a8dd23b6aaf57bc5b26aa8d94d111/src/Persistence/ObjectManager.php#L114-L119 The method should silently do nothing when called with non-Doctrine entities, not throw an exception. #### How to reproduce ```php <?php use Doctrine\ORM\ORMSetup; use Doctrine\ORM\EntityManager; $config = ORMSetup::createAttributeMetadataConfiguration([__DIR__ . '/src'], true); $config->enableNativeLazyObjects(true); $entityManager = EntityManager::create($connectionParams, $config); $nonEntity = new stdClass(); $nonEntity->someProperty = 'test'; $entityManager->initializeObject($nonEntity); // Exception: The class 'stdClass' was not found in the chain configured namespaces ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7555