api-platform / core

The server component of API Platform: hypermedia and GraphQL APIs in minutes
https://api-platform.com
MIT License
2.44k stars 869 forks source link

Installation from new Symfony project fails because of doctrine/orm:^3 #6150

Closed tacman closed 8 months ago

tacman commented 8 months ago

API Platform version(s) affected: 3.2

Description

SearchFilter.php tries to match against Types::ARRAY, which no longer exists.

https://github.com/api-platform/core/blob/main/src/Doctrine/Orm/Filter/SearchFilter.php#L370-L379

protected function getType(string $doctrineType): string
    {
        return match ($doctrineType) {
            Types::ARRAY => 'array',
            Types::BIGINT, Types::INTEGER, Types::SMALLINT => 'int',
            Types::BOOLEAN => 'bool',
            Types::DATE_MUTABLE, Types::TIME_MUTABLE, Types::DATETIME_MUTABLE, Types::DATETIMETZ_MUTABLE, Types::DATE_IMMUTABLE, Types::TIME_IMMUTABLE, Types::DATETIME_IMMUTABLE, Types::DATETIMETZ_IMMUTABLE => \DateTimeInterface::class,
            Types::FLOAT => 'float',
            default => 'string',
        };
    }

Upgrade a Symfony project to use doctrine/orm 3. Api calls then fail.

tacman commented 8 months ago

To reproduce:

symfony new api-bug --webapp && cd api-bug
composer config extra.symfony.allow-contrib true
echo "DATABASE_URL=sqlite:///%kernel.project_dir%/var/data.db" > .env.local
composer require api
echo "title,string,80,yes," | sed "s/,/\n/g"  | bin/console -a make:entity Book
bin/console doctrine:schema:update --force --complete

symfony server:start -d
symfony open:local --path=/api

Now add a Book via post

curl -X 'POST' \
  'https://127.0.0.1:8000/api/books' \
  -H 'accept: application/ld+json' \
  -H 'Content-Type: application/ld+json' \
  -d '{
  "title": "Symfony Fast Track"
}'
{
  "@id": "/api/errors/500",
  "@type": "hydra:Error",
  "title": "An error occurred",
  "detail": "Attempted to load class \"ClassUtils\" from namespace \"Doctrine\\Common\\Util\".\nDid you forget a \"use\" statement for another namespace?",
  "status": 500,
  "type": "/errors/500",
  "trace": [
    {
      "file": "/home/tac/g/trash/api-bug/vendor/symfony/ux-turbo/src/Doctrine/BroadcastListener.php",
      "line": 73,
      "function": "storeEntitiesToPublish",
      "class": "Symfony\\UX\\Turbo\\Doctrine\\BroadcastListener",
      "type": "->"
    },
    {
      "file": "/home/tac/g/trash/api-bug/vendor/symfony/doctrine-bridge/ContainerAwareEventManager.php",
      "line": 63,
      "function": "onFlush",
      "class": "Symfony\\UX\\Turbo\\Doctrine\\BroadcastListener",
      "type": "->"
    },
    {
      "file": "/home/tac/g/trash/api-bug/vendor/doctrine/orm/src/UnitOfWork.php",
      "line": 3117,
      "function": "dispatchEvent",
      "class": "Symfony\\Bridge\\Doctrine\\ContainerAwareEventManager",
      "type": "->"
    },
    {
      "file": "/home/tac/g/trash/api-bug/vendor/doctrine/orm/src/UnitOfWork.php",
      "line": 377,
      "function": "dispatchOnFlushEvent",
      "class": "Doctrine\\ORM\\UnitOfWork",
      "type": "->"
    },
    {
      "file": "/home/tac/g/trash/api-bug/vendor/doctrine/orm/src/EntityManager.php",
soyuka commented 8 months ago

will release today