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

Patch #22309: Remove "null" value of not passed name attribute #22310

Closed
wants to merge 1 commit into from
Closed

Patch #22309: Remove "null" value of not passed name attribute #22310

wants to merge 1 commit into from

Conversation

cmuench
Copy link
Contributor

@cmuench cmuench commented Apr 12, 2019

Description

If a category is updated via REST API in the "all" scope and the
category name is not sent, Magento use "null" as value for the name,
This leads into a validation error, because the category name is
required.
In this case we remove the null value out of the automatically
generated default value array. Magento will then skip the category,
because there is no change.

Fixed Issues

  1. Category Update without "name" cannot be saved in scope "all" with REST API #22309: Category Update without "name" cannot be saved in scope "all" with REST API

Manual testing scenarios

  1. Install demo data in Magento 2.3.x
  2. Try to save an existing category without the name attribute via REST API in scope "all".

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 on Travis CI are green)

If a category is updated via REST API in the "all" scope and the
category name is not sent, Magento use "null" as value for the name,
This leads into a validation error, because the category name is
required.
In this case we remove the null value out of the automatically
generated default value array. Magento will then skip the category,
because there is no change.
@m2-assistant
Copy link

m2-assistant bot commented Apr 12, 2019

Hi @cmuench. 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-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me 2.3-develop instance - deploy vanilla Magento instance

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

@ghost
Copy link

ghost commented Apr 12, 2019

@cmuench unfortunately, only members of the maintainers team are allowed to assign developers to the pull request

@@ -80,6 +80,10 @@ public function save(\Magento\Catalog\Api\Data\CategoryInterface $category)
$existingData = array_diff_key($existingData, array_flip(['path', 'level', 'parent_id']));
$existingData['store_id'] = $storeId;

if (array_key_exists('name', $existingData) && $existingData['name'] === null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of unsetting, please fix a place where name is set to null.

Are you sure such request in issue is valid?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The request is valid.
See screenshot in issue. This is a real world example. One of our customers wan't to change the the "is_active" flag. It is not possible to change the global value without to specify the name. If you send the same call with a store code it is OK.
Partial updates are supported by Magento.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@orlangur I am also not satisfied by this solution but the problem is in the framework.
The "null" value is generated by this method: \Magento\Framework\Reflection\DataObjectProcessor::buildOutputDataArray.
Do you have any good idea to handle that?

@cmuench
Copy link
Contributor Author

cmuench commented Apr 20, 2019

Fixed by PR #22362

@cmuench cmuench closed this Apr 20, 2019
@m2-assistant
Copy link

m2-assistant bot commented Apr 20, 2019

Hi @cmuench, 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.

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.

3 participants