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

Reflection: Fix null as first return type #25806

Merged

Conversation

theCapypara
Copy link
Member

@theCapypara theCapypara commented Nov 28, 2019

Description (*)

This fixes null as the first return type for methods used in the service layer.

The examples given in #25656 are now working. Additionally the Swagger schema generation no longer fails with the exception The "" data type isn't declared. Verify the type and try again..

If null is the only return type, a new exception will be thrown. It's not, see comments below

Fixed Issues

  1. M2.3.2 : Nullable getters in Service Contracts will throw a reflection error when used in the web API  #25656: M2.3.2 : Nullable getters in Service Contracts will throw a reflection error when used in the web API

Manual testing scenarios (*)

  1. Create a simple REST WebAPI endpoint, with a getter Method as described in M2.3.2 : Nullable getters in Service Contracts will throw a reflection error when used in the web API  #25656
  2. Try to open the Swagger documentation (should work now)
  3. Try to execute the API endpoint (should work now)

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@theCapypara theCapypara requested a review from YevSent as a code owner November 28, 2019 14:52
@m2-assistant
Copy link

m2-assistant bot commented Nov 28, 2019

Hi @Parakoopa. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Guide documentation.

- phpcs:ignore added because this line was not actually touched
@theCapypara
Copy link
Member Author

theCapypara commented Nov 29, 2019

I had to remove the exception I added to catch cases, where only null is defined as a return type for methods, which isn't supported by the code resolving type instances of return types.

The reason for this is, that the reflection logic also seems to be used during integration tests, and there are methods used there which actually return null. There are no errors being thrown there, so assume in those cases null is actually supported as a return type by the reflection logic. For reference, here are the logs of the integration builds:

11:34:01 [Integration-7-ce] In TypeProcessor.php line 297:
11:34:01 [Integration-7-ce]
11:34:01 [Integration-7-ce]   [InvalidArgumentException]
11:34:01 [Integration-7-ce]   No valid return type for Magento\TestModuleMysqlMq\Model\DataObjectReposito
11:34:01 [Integration-7-ce]   ry::delayedOperation() specified. Verify the return type and try again.
11:34:01 [Integration-7-ce]
11:34:01 [Integration-7-ce]
11:34:01 [Integration-7-ce] Exception trace:
11:34:01 [Integration-7-ce]  () at /var/www/html/lib/internal/Magento/Framework/Reflection/TypeProcessor.php:297
11:34:01 [Integration-7-ce]  Magento\Framework\Reflection\TypeProcessor->getGetterReturnType() at /var/www/html/lib/internal/Magento/Framework/Reflection/MethodsMap.php:173
11:34:01 [Integration-7-ce]  Magento\Framework\Reflection\MethodsMap->getMethodMapViaReflection() at /var/www/html/lib/internal/Magento/Framework/Reflection/MethodsMap.php:108
11:34:01 [Integration-7-ce]  Magento\Framework\Reflection\MethodsMap->getMethodsMap() at /var/www/html/lib/internal/Magento/Framework/Reflection/MethodsMap.php:81

This means methods that only have null as a return type will still throw the same weird exceptions mentioned in the issue (when used via webapi), but the integration tests are working again.

Methods that can return null AND a valid type are now working correctly, regardless of order.

@sidolov sidolov changed the base branch from 2.3-develop to 2.4-develop December 5, 2019 17:10
@ihor-sviziev ihor-sviziev self-assigned this Feb 17, 2020
@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev, thank you for the review.
ENGCOM-6920 has been created to process this Pull Request
✳️ @ihor-sviziev, could you please add one of the following labels to the Pull Request?

Label Description
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests
Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests
Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests

@ihor-sviziev ihor-sviziev added the Auto-Tests: Covered All changes in Pull Request is covered by auto-tests label Feb 18, 2020
@engcom-Alfa engcom-Alfa self-assigned this Feb 18, 2020
@engcom-Golf engcom-Golf self-assigned this Feb 18, 2020
@engcom-Alfa
Copy link
Contributor

✔️ QA Passed

@magento-engcom-team magento-engcom-team merged commit 7ea3af7 into magento:2.4-develop Feb 21, 2020
@m2-assistant
Copy link

m2-assistant bot commented Feb 21, 2020

Hi @Parakoopa, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@theCapypara theCapypara deleted the nullable-api-getters branch February 24, 2020 16:18
@theCapypara theCapypara added Partner: Tudock GmbH partners-contribution Pull Request is created by Magento Partner labels Apr 8, 2020
@sdzhepa sdzhepa mentioned this pull request May 9, 2022
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.

6 participants