Skip to content

LinksHandlerTrait : The class "App\Entity\EntityName" cannot be retrieved from "App\Entity\EntityName" #6059

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
xterr opened this issue Dec 20, 2023 · 5 comments
Labels

Comments

@xterr
Copy link
Contributor

xterr commented Dec 20, 2023

API Platform version(s) affected: 3.2.7

Description
RuntimeException is thrown on line 87 in LinksHandlerTrait for:

  1. Entity with a column of type enum
  2. Int BackedEnum, with a member with value = 0
  • The issue is present only when there is a value equal to 0 in the database.
  • The issue happens for single items and collections.
  • For non-enum fields value=0 is accepted and all functionality is as expected.

How to reproduce

enum StateEnum: int {
  case NEW      = 0;
  case ACTIVE   = 1;
  case INACTIVE = 2;
}

#[ORM\Entity]
#[ApiResource]
class Entity {
  #[ORM\Column(type: Types::SMALLINT, enumType: StateEnum::class)]
  #[Groups(['entity:read', 'entity:write'])]
  #[Assert\Choice(callback: [StateEnum::class, 'cases'])]
  state: StateEnum
}

Additional context
After some debugging, I observed that the data was correctly retrieved from the database.
The problem might start from ApiPlatform\GraphQl\State\Provider\ReadProvider#107
ReadProvider

@xterr xterr changed the title The class \"App\\Entity\\EntityName\" cannot be retrieved from \"App\\Entity\\EntityName\" The class "App\Entity\EntityName" cannot be retrieved from "App\Entity\EntityName" Dec 20, 2023
@xterr xterr changed the title The class "App\Entity\EntityName" cannot be retrieved from "App\Entity\EntityName" LinksHandlerTrait : The class "App\Entity\EntityName" cannot be retrieved from "App\Entity\EntityName" Dec 20, 2023
@soyuka
Copy link
Member

soyuka commented Dec 20, 2023

Are you using the enum as identifier? this isn't supported may we see the whole resource or some more informations as this is not enough?

@xterr
Copy link
Contributor Author

xterr commented Dec 20, 2023

@soyuka no. The entity has id autoincrement as the identifier.

Only normal fields typed with enum (like in the example) have this problem. (I also have setters and getters defined as i know it impacts propertyResolver)

It seems to occur only for graphql endpoint.

I also did more tests by changing the column name from state to type and other non-common names), same problem.

Thank you 👍

@soyuka
Copy link
Member

soyuka commented Dec 20, 2023

I see, can you provide a reproducer ?

@xterr
Copy link
Contributor Author

xterr commented Dec 20, 2023

I created a repository for this purpose:
https://github.com/xterr/api-platform-links-handler-trait

You can find a test case in the readme

Thank you

@soyuka soyuka added the bug label Dec 21, 2023
@GwendolenLynch
Copy link
Contributor

This looks to be fixed by #6092

The tl;dr of what was happening was right here

if ($body || null === $resourceClass || ($type && !$type->isCollection())) {

$body was equal to 0 so the loose comparison sent things down the wrong code path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants