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

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

Closed
kanduvisla opened this issue Nov 19, 2019 · 6 comments
Assignees
Labels
Component: Api Use with concrete module component label E.g. "Component: Api" + "Catalog" Event: cd-cologne19 Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@kanduvisla
Copy link
Contributor

kanduvisla commented Nov 19, 2019

Preconditions

  1. Magento 2.3.2 & 2.3-develop

Steps to reproduce

Create an interface with a nullable getter. In our scenario it was a method that could return an array of instances of another object, or null:

/**
 * @return null|\Vendor\Module\Api\Data\CompanyAddressInterface[]
 */
public function getAddresses(): ?array;

Expected result

When properly configured and used as a web API, the object should be serialized using Reflection and it's nested objects as well.

Actual result

The following error is thrown:

image

Possible cause

My guess is that when determinating the type of return class, something goes wrong when a return type can be nullable. See also the workaround:

Workaround

The current woraround that will not trigger this error and make the web API work as expected is to flip the arguments, so instead of:

/**
 * @return null|\Vendor\Module\Api\Data\CompanyAddressInterface[]
 */
public function getAddresses(): ?array;

I use:

/**
 * @return \Vendor\Module\Api\Data\CompanyAddressInterface[]|null
 */
public function getAddresses(): ?array;

Now everything works as expected, but it seems to me that this should be considered a bug.

@m2-assistant
Copy link

m2-assistant bot commented Nov 19, 2019

Hi @kanduvisla. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.3-develop instance - upcoming 2.3.x release

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

@kanduvisla do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
  • no

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Nov 19, 2019
@engcom-Charlie engcom-Charlie self-assigned this Nov 20, 2019
@m2-assistant
Copy link

m2-assistant bot commented Nov 20, 2019

Hi @engcom-Charlie. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Add label Issue: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-Charlie engcom-Charlie added Component: Api Use with concrete module component label E.g. "Component: Api" + "Catalog" Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Nov 21, 2019
@ghost ghost unassigned engcom-Charlie Nov 21, 2019
@magento-engcom-team magento-engcom-team added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Nov 21, 2019
@magento-engcom-team
Copy link
Contributor

✅ Confirmed by @engcom-Charlie
Thank you for verifying the issue. Based on the provided information internal tickets MC-29037 were created

Issue Available: @engcom-Charlie, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@m2-assistant
Copy link

m2-assistant bot commented Nov 28, 2019

Hi @Parakoopa. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

  • 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 2. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 3. If the issue is not relevant or is not reproducible any more, feel free to close it.


@theCapypara
Copy link
Member

theCapypara commented Nov 28, 2019

A related issue, which must also be fixed:
When generating the swagger schema, Magento fails, if null is the first type in the @return annotation:

<response>
<message>
The "" data type isn't declared. Verify the type and try again.
</message>
<trace>
#0 /src/app/code/Magento/Webapi/Model/Rest/Swagger/Generator.php(471): Magento\Framework\Reflection\TypeProcessor->getTypeData('') #1 /src/app/code/Magento/Webapi/Model/Rest/Swagger/Generator.php(449): Magento\Webapi\Model\Rest\Swagger\Generator->generateDefinition('') #2 /src/app/code/Magento/Webapi/Model/Rest/Swagger/Generator.php(476): Magento\Webapi\Model\Rest\Swagger\Generator->getObjectSchema(NULL, '') #3 /src/app/code/Magento/Webapi/Model/Rest/Swagger/Generator.php(449): Magento\Webapi\Model\Rest\Swagger\Generator->generateDefinition('TudockTestDataT...') #4 /src/app/code/Magento/Webapi/Model/Rest/Swagger/Generator.php(910): Magento\Webapi\Model\Rest\Swagger\Generator->getObjectSchema('TudockTestDataT...', '') #5 /src/app/code/Magento/Webapi/Model/Rest/Swagger/Generator.php(271): Magento\Webapi\Model\Rest\Swagger\Generator->generateMethodSuccessResponse(Array, Array) #6 /src/app/code/Magento/Webapi/Model/Rest/Swagger/Generator.php(252): Magento\Webapi\Model\Rest\Swagger\Generator->generateMethodResponses(Array) #7 /src/app/code/Magento/Webapi/Model/Rest/Swagger/Generator.php(170): Magento\Webapi\Model\Rest\Swagger\Generator->generatePathInfo('get', Array, 'tudockTestV1') #8 /src/app/code/Magento/Webapi/Model/AbstractSchemaGenerator.php(109): Magento\Webapi\Model\Rest\Swagger\Generator->generateSchema(Array, 'https', 'magento-github....', '/rest/all/schem...') #9 /src/app/code/Magento/Webapi/Controller/Rest/SchemaRequestProcessor.php(59): Magento\Webapi\Model\AbstractSchemaGenerator->generate(Array, 'https', 'magento-github....', '/rest/all/schem...') #10 /src/app/code/Magento/Webapi/Controller/Rest.php(188): Magento\Webapi\Controller\Rest\SchemaRequestProcessor->process(Object(Magento\Framework\Webapi\Rest\Request\Proxy)) #11 /src/lib/internal/Magento/Framework/Interception/Interceptor.php(58): Magento\Webapi\Controller\Rest->dispatch(Object(Magento\Framework\App\Request\Http)) #12 /src/lib/internal/Magento/Framework/Interception/Interceptor.php(138): Magento\Webapi\Controller\Rest\Interceptor->___callParent('dispatch', Array) #13 /src/lib/internal/Magento/Framework/Interception/Interceptor.php(153): Magento\Webapi\Controller\Rest\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http)) #14 /src/generated/code/Magento/Webapi/Controller/Rest/Interceptor.php(26): Magento\Webapi\Controller\Rest\Interceptor->___callPlugins('dispatch', Array, Array) #15 /src/lib/internal/Magento/Framework/App/Http.php(116): Magento\Webapi\Controller\Rest\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http)) #16 /src/generated/code/Magento/Framework/App/Http/Interceptor.php(24): Magento\Framework\App\Http->launch() #17 /src/lib/internal/Magento/Framework/App/Bootstrap.php(260): Magento\Framework\App\Http\Interceptor->launch() #18 /src/pub/index.php(40): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor)) #19 {main}
</trace>
</response>

theCapypara added a commit to theCapypara/magento2 that referenced this issue Nov 28, 2019
theCapypara added a commit to theCapypara/magento2 that referenced this issue Nov 28, 2019
- phpcs:ignore added because this line was not actually touched
theCapypara added a commit to theCapypara/magento2 that referenced this issue Nov 29, 2019
@magento-engcom-team
Copy link
Contributor

Hi @kanduvisla. Thank you for your report.
The issue has been fixed in #25806 by @Parakoopa in 2.4-develop branch
Related commit(s):

The fix will be available with the upcoming 2.4.0 release.

@magento-engcom-team magento-engcom-team added the Fixed in 2.4.x The issue has been fixed in 2.4-develop branch label Feb 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Api Use with concrete module component label E.g. "Component: Api" + "Catalog" Event: cd-cologne19 Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests

4 participants