You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a somewhat poor example, given that I'm using a custom type, and I should probably just fix my App\Doctrine\DBAL\Types\DateStrImmutableType->convertToPHPValue() to handle the "m/d/Y" format, but regardless of that minor nit, it turns out the offending field was 4 layers of relationships deep from the originally requested object.
It would be greatly beneficial, imo, to add some sort of improved messaging to the exception.
Proposed Fix
My quick initial naive implementation I did as a test to see if this was even actionable:
wrap the entire switch statement in Doctrine\ORM\Internal\Hydration\AbstractHydrator->gatherRowData in a try/catch block:
catch (\Doctrine\DBAL\Types\ConversionException $ex) {
throw new \Doctrine\DBAL\Types\ConversionException(\sprintf('%s, in field "%s.%s"', $ex->getMessage(), $dqlAlias, $fieldName), previous: $ex);
}
add a catch block to AbstractHydrator->hydrateAll:
Resulting error message: Could not convert database value "7/18/25" to Doctrine Type datestr_immutable. Expected format: Y-m-d, in field "App\Doctrine\Entity\External\[TABLE].[FIELD]"
A more proper fix would be to either
a. add className and fieldName properties to \Doctrine\DBAL\Types\ConversionException, or
b. extend ConversionException and add those properties to the extended class (in some ORM exception namespace)
However, there are a few possible issues I can foresee:
ObjectHydrator has a internal note: "Highly performance-sensitive code." I'm not sure what the impact of adding the try-catch exception handling would have on gatherRowData. It could (should?) probably be hoisted up to wrap the foreach block, as $fieldName would be in scope by the time the ConversionException happens.
$dqlAlias only exists in the default switch case. I don't know how to handle the other two cases. Maybe just the field name, and the hydrateAll catch block tries to figure out the column owner, a la $rsm->declaringClasses[array_search($ex->field, $rsm->fieldMappings, true)]?
What are everyone's thoughts on this? I'd be willing to submit a PR if there's any interest, or rather lack of opposition, to adding this feature.
The text was updated successfully, but these errors were encountered:
Feature Request
Summary
It would be helpful if the thrown ConversionException included the table and field of the source of the conversion exception:
This is a somewhat poor example, given that I'm using a custom type, and I should probably just fix my
App\Doctrine\DBAL\Types\DateStrImmutableType->convertToPHPValue()
to handle the "m/d/Y" format, but regardless of that minor nit, it turns out the offending field was 4 layers of relationships deep from the originally requested object.It would be greatly beneficial, imo, to add some sort of improved messaging to the exception.
Proposed Fix
My quick initial naive implementation I did as a test to see if this was even actionable:
Could not convert database value "7/18/25" to Doctrine Type datestr_immutable. Expected format: Y-m-d, in field "App\Doctrine\Entity\External\[TABLE].[FIELD]"
A more proper fix would be to either
a. add
className
andfieldName
properties to\Doctrine\DBAL\Types\ConversionException
, orb. extend
ConversionException
and add those properties to the extended class (in some ORM exception namespace)However, there are a few possible issues I can foresee:
ObjectHydrator
has a internal note: "Highly performance-sensitive code." I'm not sure what the impact of adding the try-catch exception handling would have ongatherRowData
. It could (should?) probably be hoisted up to wrap theforeach
block, as$fieldName
would be in scope by the time theConversionException
happens.the$dqlAlias
only exists in the default switch case. I don't know how to handle the other two cases. Maybe just the field name, andhydrateAll
catch block tries to figure out the column owner, a la$rsm->declaringClasses[array_search($ex->field, $rsm->fieldMappings, true)]
?What are everyone's thoughts on this? I'd be willing to submit a PR if there's any interest, or rather lack of opposition, to adding this feature.
The text was updated successfully, but these errors were encountered: