-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Compatibility issue with Symfony 7.2: Cannot create a "Symfony\Component\TypeInfo\Type\NullableType" error #59137
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
Comments
/cc @mtarld |
Here is a test that allows to reproduce the error: public function testNullable()
{
$mixed = Type::mixed();
$this->assertSame($mixed, Type::nullable($mixed));
} Status: Reviewed |
Isn't that fixed already? api-platform/core@4d7deea Also, not a symfony issue imo. |
Indeed, sounds like an issue in API Platform here. And, IMHO that doesn't make sense to convert a mixed to its nullable version as it's already nullable. Therefore, this exception is logical. |
What's a bit unfortunate though is that |
Agreed. What I had in mind was to update the public static function nullable(Type $type): Type
{
if ($type->isNullable()) {
return $type;
}
return new NullableType($type);
} But, even if 7.2 just has been released, this will update the return type and therefore will be a BC break 🫤 |
If it's the best fix for the case at hand I'd agree to do it as a bugfix given it is broken today. |
…lable type (mtarld) This PR was merged into the 7.2 branch. Discussion ---------- [TypeInfo] Make `Type::nullable` method no-op on every nullable type | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Issues | Fix #59137 | License | MIT Make `Type::nullable` method no-op on every nullable type, not only on `NullableType` types. Commits ------- 640a8d5 [TypeInfo] Fix handle nullable with mixed
Symfony version(s) affected
7.2.0
Description
After upgrading Symfony to version 7.2, my project stopped working with the following error:
Cannot create a "Symfony\Component\TypeInfo\Type\NullableType" with "mixed" because it is already nullable in . (which is being imported from "/var/www/back/config/routes/api_platform.yaml"). Make sure there is a loader supporting the "api_platform" type.
This error points to the api_platform type in my config/routes/api_platform.yaml file:
api_platform:
resource: .
type: api_platform
prefix: /api
The issue seems to be related to changes introduced in Symfony 7.2, specifically in the redesigned TypeInfo component, as explained in this blog post: New in Symfony 7.2: Redesigned TypeInfo Component.
It appears that the mixed type is now always nullable, and API Platform may not handle this properly. Before the update, everything worked fine with Symfony 7.1.
How to reproduce
Steps to Reproduce:
Use Symfony 7.2 and the latest version of API Platform.
Create a basic api_platform.yaml file like the one above.
Access any route managed by API Platform.
Expected Behavior:
The routes should be processed normally without any errors.
Actual Behavior:
The error mentioned above is thrown, and the application fails to start.
http://prntscr.com/tT42Y1r46TGI
Steps Taken:
Updated all dependencies to their latest versions.
Cleared the Symfony cache (php bin/console cache:clear).
Verified that the error disappears when downgrading Symfony to version 7.1.
Please let me know if further details or logs are needed.
Possible Solution
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: