Skip to content
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

Fatal error since >= 3.32.1: TypeError: TypedPropertiesDriver::shouldTypeHintInsideUnion #1584

Open
nocive opened this issue Jan 20, 2025 · 4 comments
Labels
Union Types Support for Union Types

Comments

@nocive
Copy link

nocive commented Jan 20, 2025

After the introduction of #1571 we experience a fatal error in a previously working codebase while serializing a doctrine entity object:

"exception": {
  "class": "TypeError",
  "message": "JMS\\Serializer\\Metadata\\Driver\\TypedPropertiesDriver::shouldTypeHintInsideUnion(): Argument #1 ($reflectionType) must be of type ReflectionNamedType, ReflectionIntersectionType given, called in vendor/jms/serializer/src/Metadata/Driver/TypedPropertiesDriver.php on line 184",
  "code": "0",
  "file": "vendor/jms/serializer/src/Metadata/Driver/TypedPropertiesDriver.php:192",
  "trace": [
    "vendor/jms/serializer/src/Metadata/Driver/TypedPropertiesDriver.php:184",
    "vendor/jms/serializer/src/Metadata/Driver/TypedPropertiesDriver.php:115",
    "vendor/jms/metadata/src/Driver/LazyLoadingDriver.php:38",
    "vendor/jms/metadata/src/MetadataFactory.php:111",
    "vendor/jms/serializer-bundle/Debug/TraceableMetadataFactory.php:42",
    "vendor/jms/serializer/src/GraphNavigator/SerializationGraphNavigator.php:234",
    "vendor/jms/serializer/src/JsonSerializationVisitor.php:101",
    "vendor/jms/serializer/src/GraphNavigator/SerializationGraphNavigator.php:172",
    "vendor/jms/serializer/src/JsonSerializationVisitor.php:101",
    "vendor/jms/serializer/src/GraphNavigator/SerializationGraphNavigator.php:172",
    "vendor/jms/serializer/src/Serializer.php:256",
    "vendor/jms/serializer/src/Serializer.php:163",
    ....

I saw that there are already other issues reported related to unions (such as #1566) but I didn't see any exhibiting the same symptoms so I'm reporting it just in case.

For now we're forced to pin 3.31.1 to work around the issue.

Thank you for the great work.

@nocive nocive changed the title Fatal error since >= 3.32.1: Uncaught PHP Exception TypeError: TypedPropertiesDriver::shouldTypeHintInsideUnion Fatal error since >= 3.32.1: TypeError: TypedPropertiesDriver::shouldTypeHintInsideUnion Jan 20, 2025
@scyzoryck
Copy link
Collaborator

Hi @nocive !

Could you share some example how to reproduce the issue? I guess we need some specific property type, but not sure how to reproduce it 😓

Best, Marcin.

@scyzoryck scyzoryck added the Union Types Support for Union Types label Jan 28, 2025
@nocive
Copy link
Author

nocive commented Jan 29, 2025

@scyzoryck 👋

Might be a bit tricky to isolate it and figure out where it's coming from, but I'll try.

My best guess without diving deeper is that it could be caused by property declarations of the likes:

private (Collection&Selectable)|ArrayCollection $prop;

Would that make sense as a possible culprit from your pov?

@scyzoryck
Copy link
Collaborator

Thanks! Looks like a good candidate. We do not have such case in our test case. I'm wondering what should be the the type for deserialisation.

  1. None - so it should be configured in other way
  2. ArrayCollection

@nocive
Copy link
Author

nocive commented Jan 30, 2025

This is a doctrine entity ManyToMany relational property, hence the complex type.
It's a Collection&Selectable when retrieved from the db and an ArrayCollection when instantiated manually.

Probably doing nothing is the safer option but I think that preserving the previous behavior before the introduction of #1571 should be the way to go.

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

No branches or pull requests

2 participants