Skip to content

Commit f55340b

Browse files
Spamerczclaude
andcommitted
fix: handle DocumentNotFound for nullable ElasticEntity properties
When resolving a nullable AbstractElasticEntity property and the referenced document doesn't exist in ES, set the value to null instead of letting DocumentNotFound propagate and kill the entire parent entity creation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 70bac8b commit f55340b

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/Factory/EntityFactory.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,19 @@ class: $value[\Spameri\Elastic\Model\Insert\PrepareEntityArray::ENTITY_CLASS],
243243
$this->identityMap->uninitializedEntityList[$propertyTypeName][$value][$property->getName()][$hit->id()] = $class;
244244

245245
} else {
246-
$propertyValue = $entityManager->find(
247-
id: $value,
248-
class: $propertyTypeName,
249-
);
246+
try {
247+
$propertyValue = $entityManager->find(
248+
id: $value,
249+
class: $propertyTypeName,
250+
);
251+
} catch (\Spameri\Elastic\Exception\DocumentNotFound $e) {
252+
if ($reflectionPropertyType->allowsNull()) {
253+
$propertyValue = null;
254+
$setNull = true;
255+
} else {
256+
throw $e;
257+
}
258+
}
250259
}
251260

252261
} elseif ($this->container->getByType($propertyTypeName, false) !== null) {

0 commit comments

Comments
 (0)