Closed MeCapron closed 2 years ago
Hi @MeCapron. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:
Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:
@magento give me 2.4-develop instance
- upcoming 2.4.x release
For more details, review the Magento Contributor Assistant documentation.
Add a comment to assign the issue: @magento I am working on this
To learn more about issue processing workflow, refer to the Code Contributions.
Join Magento Community Engineering Slack and ask your questions in #github channel.
:warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
:clock10: You can find the schedule on the Magento Community Calendar page.
:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.
:movie_camera: You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel
:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel
Hi @engcom-Delta. 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: :point_down:
[ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).Details
If 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.4-develop
branchDetails
- Add the comment @magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.4-develop
branch, please, add the label Reproduced on 2.4.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.
Hi @engcom-Hotel. 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: :point_down:
[ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).Details
If 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.4-develop
branchDetails
- Add the comment @magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.4-develop
branch, please, add the label Reproduced on 2.4.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.
Hi @engcom-Echo. 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: :point_down:
Issue: Format is valid
will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid
appears.Issue: Clear Description
label to the issue by yourself.Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.2.4-develop
branch@magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure. 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.Hi @MeCapron,
Thank you for reporting the issue.
However, we tried to reproduce it on Magento 2.4-dev but the issue is not reproducible.
Steps followed to reproduce issue:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
<extension_attributes for="Magento\Customer\Api\Data\CustomerInterface">
<attribute code="date" type="DateTime"/>
</extension_attributes>
</config>
Cleard cache and run di:compile to generate new files. bin/magento c:c bin/magento setup:di:compile
Following code generated after execution of di:compile under file “generated/code/Magento/Customer/Api/Data/CustomerExtensionInterface.php”
<?php namespace Magento\Customer\Api\Data;
/**
ExtensionInterface class for @see \Magento\Customer\Api\Data\CustomerInterface */ interface CustomerExtensionInterface extends \Magento\Framework\Api\ExtensionAttributesInterface { /**
/**
3. Tested the generated code by using the below mention code
$customerDataObject = $this->customerRepository->getById($customerId); $extension = $customerDataObject->getExtensionAttributes(); $extension->setDate( \DateTime::createFromFormat( 'Y-m-d', date('Y-m-d') ) ); echo $extension->getDate()->getTimestamp();
4. The above code successfully, without any error. (See the attached output screenshot).
If the issue still persists at your end then please provide some more details or provide the exact steps, accordingly, I’ll try to reproduce it again.
Thanks
Hello, thanks for watching out this issue. I missed some information. Very sorry about this.
This issue still persists in this way :
Everything you did was correct, then you can try to use the buildOutputDataArray.
<?php
declare(strict_types=1);
namespace MyVendor\MyModule\Helper;
use Magento\Framework\Reflection\DataObjectProcessor;
class CustomerPlugin
{
private DataObjectProcessor $dataObjectProcessor;
private CustomerRepositoryInterface $customerRepository;
public function __construct(
DataObjectProcessor $dataObjectProcessor,
CustomerRepositoryInterface $customerRepository
) {
$this->dataObjectProcessor = $dataObjectProcessor;
$this->customerRepository = $customerRepository;
}
public function testGetCustomer(): void
{
$customer = $this->customerRepository->getById(1);
$customer->getExtensionAttributes()->setDate(new \DateTime());
$this->dataObjectProcessor->buildOutputDataArray($customer, CustomerInterface::class);
}
Hi @MeCapron,
I understood the issue now which you are getting but it seems it's not an actual issue, after debugging it some more I found that buildOutputDataArray($dataObject, $dataObjectType) needs an object and its type, and on the basis of object type it loads the interface. But in our case, we are using the standard PHP date time object for which Magento doesn’t have an interface available. To solve this issue we need to use Magento’s standard DateTime library.
Update your extension_attributes.xml with the following code:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
<extension_attributes for="Magento\Customer\Api\Data\CustomerInterface">
<attribute code="date" type="Magento\Framework\Stdlib\DateTime"/>
</extension_attributes>
</config>
And while using, you have to use Stdlib\DateTime() instead the standard DateTime object. $customerDataObject->getExtensionAttributes()->setDate(new Stdlib\DateTime());
Hope it helps. Let me know if you are still face this issue or provide more relevant details if you think it is Magento core issue ?
Thanks
Dear @MeCapron,
We have noticed that this issue has not been updated for a period of 14 Days. Hence we assume that this issue is fixed now, so we are closing it. Please raise a fresh ticket or reopen this ticket if you need more assistance on this.
Regards
Hi @MeCapron,
I understood the issue now which you are getting but it seems it's not an actual issue, after debugging it some more I found that buildOutputDataArray($dataObject, $dataObjectType) needs an object and its type, and on the basis of object type it loads the interface. But in our case, we are using the standard PHP date time object for which Magento doesn’t have an interface available. To solve this issue we need to use Magento’s standard DateTime library.
Update your extension_attributes.xml with the following code:
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd"> <extension_attributes for="Magento\Customer\Api\Data\CustomerInterface"> <attribute code="date" type="Magento\Framework\Stdlib\DateTime"/> </extension_attributes> </config>
And while using, you have to use Stdlib\DateTime() instead the standard DateTime object. $customerDataObject->getExtensionAttributes()->setDate(new Stdlib\DateTime());
Hope it helps. Let me know if you are still face this issue or provide more relevant details if you think it is Magento core issue ?
Thanks
Hi!
I do not really aggree about using Magento main DateTime. What about external objects that are using DateTime of any kind of PHP object? Would it mean that if the core function has no docblock, we will just skip it? Plus, you are blocking the use of external objects that are not part of Magento system (such as serialized DTOs from API calls)
I think that all of the native PHP objects should not be part of the reflection in this system, or should be handled without any doc block (which can not be done in some cases).
What do you think about this?
Melvin
Dear @MeCapron,
We have noticed that this issue has not been updated for a period of 14 Days. Hence we assume that this issue is fixed now, so we are closing it. Please raise a fresh ticket or reopen this ticket if you need more assistance on this.
Regards
Hello,
Can you reopen this issue please? This is still an issue.
Thanks
Preconditions (*)
Steps to reproduce (*)
1 exception(s): Exception #0 (InvalidArgumentException): Each getter must have a doc block. See DateTime::format()
Expected result (*)
DateTime
built-in must be ignored as\Magento\Framework\Phrase
isActual result (*)
1 exception(s): Exception #0 (InvalidArgumentException): Each getter must have a doc block. See DateTime::format()
Possible solution
https://github.com/magento/magento2/blob/2.4.2-p2/lib/internal/Magento/Framework/Reflection/DataObjectProcessor.php#L114
we could replace this line by :
and https://github.com/magento/magento2/blob/2.4.2-p2/lib/internal/Magento/Framework/Reflection/DataObjectProcessor.php#L120
We could also maybe add a di.xml field to allow such configuration or ignoring specific types. I can't measure the impact of the latest solution though.
Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.