mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
PHP error thrown if a one-to-one relationship cannot be retrieved #6833
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @gregtyler on GitHub (Sep 21, 2021).
Bug Report
Summary
PHP error thrown if a one-to-one relationship cannot be retrieved.
I can't profess to understand this too much, but it has come up in live system due to a combination of Doctrine, JMSSerializer and the SoftDeleteable filter from doctrine-extensions. I've managed to narrow it down to the following:
Current behavior
When
UnitOfWork->createEntityis called, it fetches related records to make them part of the object returned. For bidirectional one-to-one relationships, in certain circumstances, it usesEntityManager->findto do this, then callsspl_object_hash()andReflectionProperty->setValue()with the result.If
finddoesn't find an object then it will returnnull, which is an invalid argument to both of those functions. Hence one of the following errors occurs:(The first error is what happens when I recreate locally, the second is what we saw on our live system. This has only started happening since upgrading to PHP 8.)
I believe the result of
Entitymanager->findneeds to be checked to ensure it is an object.How to reproduce
See #9028 for a failing test case and suggested fix.
This throws:
Expected behavior
The error shouldn't throw and
$cart->customershould be null.