[PR #12173] Fix no-op for initializeObject() and isUnitializedObject() when object is not a mapped entity #13544

Open
opened 2026-01-22 16:17:27 +01:00 by admin · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/doctrine/orm/pull/12173
Author: @SherinBloemendaal
Created: 9/19/2025
Status: 🔄 Open

Base: 3.6.xHead: fix-initialize-object-for-native-lazy-objects-no-op


📝 Commits (1)

  • 788faa0 Fix no-op for initializeObject() and isUnitializedObject() when object is not a mapped entity

📊 Changes

2 files changed (+96 additions, -3 deletions)

View changed files

📝 src/UnitOfWork.php (+12 -3)
tests/Tests/ORM/Functional/Ticket/GH12172Test.php (+84 -0)

📄 Description

Fix initializeObject() and isUnitializedObject() to be no-op for non-managed objects with native lazy objects

This fix wraps getClassMetadata() calls in try/catch blocks to handle non-entity objects gracefully while preserving functionality for valid Doctrine entities (including detached ones after clear()).

I went with the try/catch approach since isInIdentityMap() also internally calls getClassMetadata(), but I'm open to better solutions if there are any.

Changes:

  • UnitOfWork::initializeObject(): Add try/catch around metadata access
  • UnitOfWork::isUninitializedObject(): Add try/catch around metadata access

Fixes #12172


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/doctrine/orm/pull/12173 **Author:** [@SherinBloemendaal](https://github.com/SherinBloemendaal) **Created:** 9/19/2025 **Status:** 🔄 Open **Base:** `3.6.x` ← **Head:** `fix-initialize-object-for-native-lazy-objects-no-op` --- ### 📝 Commits (1) - [`788faa0`](https://github.com/doctrine/orm/commit/788faa003d9e4a99dc2f6e114906d8737ed3969f) Fix no-op for initializeObject() and isUnitializedObject() when object is not a mapped entity ### 📊 Changes **2 files changed** (+96 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `src/UnitOfWork.php` (+12 -3) ➕ `tests/Tests/ORM/Functional/Ticket/GH12172Test.php` (+84 -0) </details> ### 📄 Description Fix initializeObject() and isUnitializedObject() to be no-op for non-managed objects with native lazy objects This fix wraps `getClassMetadata()` calls in try/catch blocks to handle non-entity objects gracefully while preserving functionality for valid Doctrine entities (including detached ones after `clear()`). I went with the try/catch approach since `isInIdentityMap()` also internally calls `getClassMetadata()`, but I'm open to better solutions if there are any. **Changes:** - `UnitOfWork::initializeObject()`: Add try/catch around metadata access - `UnitOfWork::isUninitializedObject()`: Add try/catch around metadata access Fixes #12172 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
admin added the pull-request label 2026-01-22 16:17:27 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#13544