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

Type error thrown by attributesMetadata query #12

Open
aligent-lturner opened this issue May 18, 2023 · 0 comments
Open

Type error thrown by attributesMetadata query #12

aligent-lturner opened this issue May 18, 2023 · 0 comments

Comments

@aligent-lturner
Copy link

The attributesMetadata query can result in a type error being thrown:

[2023-05-18T06:39:53.610798+00:00] report.ERROR: Magento\PageBuilderPwa\Plugin\UiInputTypePageBuilder::afterGetAttributeMetadata(): Argument #2 ($result) must be of type array, null given, called in /app/vendor/magento/framework/Interception/Interceptor.php on line 146

GraphQL (2:3)
1: query {
2:   attributesMetadata(
     ^
3:     entityType: PRODUCT,
 {"exception":"[object] (GraphQL\\Error\\Error(code: 0): Magento\\PageBuilderPwa\\Plugin\\UiInputTypePageBuilder::afterGetAttributeMetadata(): Argument #2 ($result) must be of type array, null given, called in /app/vendor/magento/framework/Interception/Interceptor.php on line 146 at /app/vendor/webonyx/graphql-php/src/Error/Error.php:153)
[previous exception] [object] (TypeError(code: 0): Magento\\PageBuilderPwa\\Plugin\\UiInputTypePageBuilder::afterGetAttributeMetadata(): Argument #2 ($result) must be of type array, null given, called in /app/vendor/magento/framework/Interception/Interceptor.php on line 146 at /app/vendor/magento/module-page-builder-pwa/Plugin/UiInputTypePageBuilder.php:43)"} []
[2023-05-18T06:39:53.610798+00:00] report.ERROR: Magento\PageBuilderPwa\Plugin\UiInputTypePageBuilder::afterGetAttributeMetadata(): Argument #2 ($result) must be of type array, null given, called in /app/vendor/magento/framework/Interception/Interceptor.php on line 146

The function afterGetAttributeMetadata has the $result parameter typed as array -

public function afterGetAttributeMetadata(
AttributeMetadata $subject,
array $result,
AttributeInterface $attribute
): array {

However, the function it is plugging into can return void (i.e. null) -

* @return array|void
* @throws GraphQlInputException
* @throws \Magento\Framework\Exception\RuntimeException
*/
public function getAttributeMetadata(AttributeInterface $attribute, int $storeId, string $entityType)
{
if (!$attribute->getFrontendInput()) {
return;
}

The plugin should handle this case by changing the input parameter type to ?array, and handling the case where it is null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant