Skip to content

Array to string conversion when invalid value in enum array column #11796

@maximecolin

Description

@maximecolin

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

  1. Create an entity with an array of enum (example bellow)
  2. Add in database an array containing a value not the enum cases
  3. Fetch the entity

I also created a test that reproduce this error : #11795

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions