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

[PropertyInfo] Check if property is nullable when using ReflectionExtractor #57708

Merged
merged 1 commit into from
Jul 26, 2024

Conversation

benjilebon
Copy link
Contributor

Q A
Branch? 7.1
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #57707
License MIT

When $type was resolved into a CollectionType with an adder mutator on the given $class, the replaced $type ignored if the actual property was nullable or not, causing the returned Type to always report as non nullable even when given property was declared with a null union type or a ? (?array for example)

See issue for more information and an example case

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 7.2 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@OskarStark OskarStark changed the title [PropertyInfo] Check if property is nullable when using ReflectionExt… [PropertyInfo] Check if property is nullable when using ReflectionExtractor Jul 12, 2024
@OskarStark OskarStark requested a review from xabbuh July 18, 2024 05:19
@@ -548,6 +548,7 @@ public static function typeProvider(): iterable
yield ['collection', Type::list(Type::object(\DateTimeImmutable::class)), null, null];
yield ['nestedCollection', Type::list(Type::list(Type::string())), null, null];
yield ['mixedCollection', Type::array(), null, null];
yield ['nullableTypedCollection', Type::nullable(Type::list(Type::object(Dummy::class))), null, null];
Copy link
Member

@xabbuh xabbuh Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should expand provideLegacyTypes() in the same way to ensure that the behaviour of the old and new type system matches

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, amended to my last commit

@@ -865,6 +868,7 @@ public function testTypedProperties()
$this->assertEquals(Type::list(Type::string()), $this->extractor->getType(Php74Dummy::class, 'stringCollection'));
$this->assertEquals(Type::nullable(Type::int()), $this->extractor->getType(Php74Dummy::class, 'nullableWithDefault'));
$this->assertEquals(Type::array(), $this->extractor->getType(Php74Dummy::class, 'collection'));
$this->assertEquals(Type::nullable(Type::list(Type::object(Dummy::class))), $this->extractor->getType(Php74Dummy::class, 'nullableTypedCollection'));
Copy link
Member

@xabbuh xabbuh Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should expand testTypedPropertiesLegacy() in the same way to ensure that the behaviour of the old and new type system matches

@benjilebon
Copy link
Contributor Author

After testing, it seems the legacy type system is also affected by the same problem reported in linked issue #57707, which means this issue also affects 6.4

@xabbuh do you have any advice on how to proceed ? Should i open another PR based on 6.4 and provide the fix for the old type system here ?

@xabbuh
Copy link
Member

xabbuh commented Jul 22, 2024

Yes please, maybe even 5.4 instead of 6.4 if that’s affected too.

@benjilebon
Copy link
Contributor Author

benjilebon commented Jul 22, 2024

Yes please, maybe even 5.4 instead of 6.4 if that’s affected too.

Done on #57802, i've updated the relevant issue to correct the affected versions

fabpot added a commit that referenced this pull request Jul 26, 2024
…mMutator on CollectionType (benjilebon)

This PR was merged into the 5.4 branch.

Discussion
----------

[PropertyInfo] Fix nullable value returned from extractFromMutator on CollectionType

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #57707
| License       | MIT

Follow-up on #57708 to provide the fix for the legacy type system on the 5.4 branch

Commits
-------

6d77170 [PropertyInfo] Fix nullable value returned from extractFromMutator on CollectionType
@fabpot
Copy link
Member

fabpot commented Jul 26, 2024

Thank you @benjilebon.

@fabpot fabpot merged commit c369803 into symfony:7.1 Jul 26, 2024
9 of 10 checks passed
@fabpot fabpot mentioned this pull request Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants