-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Description
Bug Report
| Q | A |
|---|---|
| Version | 3.3.1 |
| Previous Version if the bug is a regression | not sure, it worked some time ago in 2.x |
Summary
When querying an entity having an array of enum containing a value that does not exists in the PHP enum, I got the following error:
Uncaught PHP Exception ErrorException: "Warning: Array to string conversion" at SimpleObjectHydrator.php line 148 {"exception":"[object] (ErrorException(code: 0): Warning: Array to string conversion at /srv/app/back/vendor/doctrine/orm/src/Internal/Hydration/SimpleObjectHydrator.php:148)"}
Current behavior
Using a json column with enumType, if the database contains a value that is not in the enum, so an exception is thrown by AbstractHydrator::buildEnum then converted to another exception in SimpleObjectHydrator. During this conversion, the original value is casted into string. In case of array of enum (json or simple array), $originalValue contains an array of string that can not be casted to string. So we got the "Array to string conversion" error instead of a proper error about a case not listed in the enum.
This case is pretty common, for exemple when a case have been removed from the PHP enum, or when a value that have been added on a branch, when switching to another branch, the value is still in the database but does not exist anymore on the PHP enum.
Expected behavior
A proper exception explaining a case in the database is not listed in the enum like for single enum case columns.
How to reproduce
- Create an entity with an array of enum (example bellow)
- Add in database an array containing a value not the enum cases
- Fetch the entity
I also created a test that reproduce this error : #11795