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

Magento 2.3.4 Quote Address Extension Attribute Issue #26682

Open
NathMorgan opened this issue Feb 3, 2020 · 8 comments
Open

Magento 2.3.4 Quote Address Extension Attribute Issue #26682

NathMorgan opened this issue Feb 3, 2020 · 8 comments

Comments

@NathMorgan
Copy link
Contributor

@NathMorgan NathMorgan commented Feb 3, 2020

Preconditions (*)

  1. Using Magento 2.3.4
  2. USing a custom extension attribute on Magento\Quote\Api\Data\AddressInterface Example module here: https://github.com/NathMorgan/module-test-module

Steps to reproduce (*)

  1. Sending a post request to estimate-shipping-methods containing a extension_attributes

For example a post request to /rest/default/V1/guest-carts/{cartId}/estimate-shipping-methods with the following example data {"address":{"street":["Example High Street"],"city":"Example City","region_id":null,"region":null,"country_id":"GB","postcode":"TES 01","company":"Example Company","telephone":"0000 00000","fax":null,"extension_attributes":{"test_attribute":"2"}}}

Expected result (*)

  1. Above action completed successfully

Actual result (*)

  1. 500 Error with the message Uncaught Error: Call to a member function setDiscounts() on array in /var/www/html/vendor/magento/module-sales-rule/Model/Quote/Discount.php: 117

This issue seems to be introduced with this commit: 6900c38

This seems to effect any extension attribute set on Magento\Quote\Api\Data\AddressInterface that is not a object

@magento-deployment-service

This comment has been minimized.

Copy link

@magento-deployment-service magento-deployment-service bot commented Feb 3, 2020

Thanks for opening this issue!

@m2-assistant

This comment has been minimized.

Copy link

@m2-assistant m2-assistant bot commented Feb 3, 2020

Hi @NathMorgan. 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.4-develop instance - upcoming 2.4.x release

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

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

  • yes
  • no

@magento-deployment-service

This comment has been minimized.

Copy link

@magento-deployment-service magento-deployment-service bot commented Feb 3, 2020

Thanks for opening this issue!

@NathMorgan

This comment has been minimized.

Copy link
Contributor Author

@NathMorgan NathMorgan commented Feb 4, 2020

Currently working on a fix

@NathMorgan NathMorgan self-assigned this Feb 4, 2020
@m2-assistant

This comment has been minimized.

Copy link

@m2-assistant m2-assistant bot commented Feb 4, 2020

Hi @NathMorgan. 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.4-develop branch

    Details- 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!


@m2-backlog m2-backlog bot moved this from Ready for QA to Dev in Progress in Community Backlog Feb 4, 2020
@m2-backlog m2-backlog bot moved this from Dev in Progress to PR In Progress in Community Backlog Feb 5, 2020
@Swahjak

This comment has been minimized.

Copy link

@Swahjak Swahjak commented Feb 10, 2020

This seems to be specifically caused by 6900c38#diff-0dba08a1fa5d66da0b3c252c4949907eR106 which populates the extension attribute. Then when it passes through https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Quote/Model/ShippingMethodManagement.php#L312 it will be converted to array by the \Magento\Framework\Reflection\DataObjectProcessor. Then the addData will blindly overwrite extension_attributes with an array value.

This could be a 'custom' implementation error only, because this will only happen if the discount collector is called before (any public function that depends on getShippingMethods) ShippingMethodManager.

On a side note; this would also cause errors if any other extension attribute is added that doesn't default to null.

@Swahjak

This comment has been minimized.

Copy link

@Swahjak Swahjak commented Feb 11, 2020

Dug in a little deeper and in my opinion the solution / problem is this line https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Quote/Model/ShippingMethodManagement.php#L312

I think there are two solutions to the problem:

  1. Since 'extraAddressData' uses the \Magento\Framework\Reflection\DataObjectProcessor it would make sense to restore the data using the Magento\Framework\Webapi\ServiceInputProcessor to restore the data. This already has build in support for extension attributes. Although it would be more consistent if the \Magento\Framework\Reflection\DataObjectProcessor would also be replaced with Magento\Framework\Webapi\ServiceOutputProcessor (although the more or less give the same result).
  2. Add a line right after the add / extract data line $shippingAddress->setExtensionAttributes($address->getExtensionAttributes());.
    (3. Don't break stuff in minor releases)

The second option is the easiest to implement but doen't really 'fix' the issue, it just works around the issue in a non-standard way.

Edit: Strike the first solution. I thought the ServiceInputProcessor could be used as a 'hydrator' but it can not. This would require some ugly recursive merge which would most definitely cause issues.

@NathMorgan

This comment has been minimized.

Copy link
Contributor Author

@NathMorgan NathMorgan commented Feb 12, 2020

@Swahjak Sadly the 2nd method is not as simple due to the fact that the $address param can be multiple diferent class types (That contain there own type of extension attributes). I've currently pushing up a change that was done to "fix" this (Only sets data if both the $address and the $shippingAddress extension attributes match)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Community Backlog
  
PR In Progress
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.