fix(custom-fields) : forcer initializeObject pour vraiment charger le proxy
Auto Tag Develop / tag (push) Successful in 10s
Auto Tag Develop / tag (push) Successful in 10s
Le helper ensureCustomFieldExists (commitaf13dc0) appelait $cf->getId() pour déclencher l'init du proxy, mais sur un proxy Doctrine getId() retourne directement l'identifiant stocké dans le proxy (la clé utilisée pour le construire) sans appeler __load(). L'EntityNotFoundException n'était donc jamais levée dans le helper et le crash sortait quand même sur getName() ligne 973. Remplacement par EntityManager::initializeObject() qui appelle __load() et propage bien l'exception. Même correction appliquée à ensurePieceExists() dans les deux contrôleurs (le bug y était masqué par la migration FK CASCADE/SET NULL livrée dans le commit003e419).
This commit is contained in:
@@ -298,8 +298,9 @@ class CustomFieldValueController extends AbstractController
|
||||
|
||||
/**
|
||||
* Returns the Piece if its underlying row still exists in DB, otherwise null.
|
||||
* Forces a lazy proxy to initialize via getId() and swallows EntityNotFoundException
|
||||
* so an orphan link to a deleted piece doesn't crash custom-field value writes.
|
||||
* getId() on a Doctrine proxy does NOT trigger __load(), so we force the proxy
|
||||
* to initialize explicitly to handle orphan links here instead of crashing on
|
||||
* the first real getter.
|
||||
*/
|
||||
private function ensurePieceExists(?Piece $piece): ?Piece
|
||||
{
|
||||
@@ -307,7 +308,7 @@ class CustomFieldValueController extends AbstractController
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
$piece->getId();
|
||||
$this->entityManager->initializeObject($piece);
|
||||
|
||||
return $piece;
|
||||
} catch (EntityNotFoundException) {
|
||||
@@ -316,8 +317,10 @@ class CustomFieldValueController extends AbstractController
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as ensurePieceExists() but for CustomField, to keep orphan CFVs from
|
||||
* crashing the value endpoints.
|
||||
* getId() on a Doctrine proxy returns the identifier without triggering __load(),
|
||||
* so it never raises EntityNotFoundException even if the row is gone. Force the
|
||||
* proxy to initialize explicitly so an orphan CFV is handled here instead of
|
||||
* crashing on the first real getter.
|
||||
*/
|
||||
private function ensureCustomFieldExists(?CustomField $cf): ?CustomField
|
||||
{
|
||||
@@ -325,7 +328,7 @@ class CustomFieldValueController extends AbstractController
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
$cf->getId();
|
||||
$this->entityManager->initializeObject($cf);
|
||||
|
||||
return $cf;
|
||||
} catch (EntityNotFoundException) {
|
||||
|
||||
@@ -815,8 +815,9 @@ class MachineStructureController extends AbstractController
|
||||
|
||||
/**
|
||||
* Returns the Piece if its underlying row still exists in DB, otherwise null.
|
||||
* Forces a lazy proxy to initialize via getId() and swallows EntityNotFoundException
|
||||
* so a stale FK (orphan link to a deleted piece) doesn't crash the whole machine view.
|
||||
* getId() on a Doctrine proxy does NOT trigger __load() (the id is the key used
|
||||
* to build the proxy), so we force initialization via initializeObject() to
|
||||
* surface a stale FK here instead of crashing on the first real getter.
|
||||
*/
|
||||
private function ensurePieceExists(?Piece $piece): ?Piece
|
||||
{
|
||||
@@ -824,7 +825,7 @@ class MachineStructureController extends AbstractController
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
$piece->getId();
|
||||
$this->entityManager->initializeObject($piece);
|
||||
|
||||
return $piece;
|
||||
} catch (EntityNotFoundException) {
|
||||
@@ -833,9 +834,10 @@ class MachineStructureController extends AbstractController
|
||||
}
|
||||
|
||||
/**
|
||||
* Same defensive pattern as ensurePieceExists() but for CustomField.
|
||||
* A CustomFieldValue may carry a stale FK to a deleted CustomField; touching
|
||||
* the lazy proxy raises EntityNotFoundException and 500s the machine view.
|
||||
* Returns the CustomField if its underlying row still exists, otherwise null.
|
||||
* getId() on a Doctrine proxy does NOT trigger __load() — the id is the key used
|
||||
* to build the proxy. We force initialization explicitly so a stale FK to a
|
||||
* deleted CustomField surfaces here instead of crashing on getName() later.
|
||||
*/
|
||||
private function ensureCustomFieldExists(?CustomField $cf): ?CustomField
|
||||
{
|
||||
@@ -843,7 +845,7 @@ class MachineStructureController extends AbstractController
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
$cf->getId();
|
||||
$this->entityManager->initializeObject($cf);
|
||||
|
||||
return $cf;
|
||||
} catch (EntityNotFoundException) {
|
||||
|
||||
Reference in New Issue
Block a user