woocommerce / woocommerce-blocks

(Deprecated) This plugin has been merged into woocommerce/woocommerce
https://wordpress.org/plugins/woo-gutenberg-products-block/
GNU General Public License v3.0
403 stars 219 forks source link

PHP Notice: Undefined index: key #6963

Closed NTShop closed 2 years ago

NTShop commented 2 years ago

Describe the bug

The plugin is causing this PHP notice when editing a page in the backend:

Notice: Undefined index: key in /var/www/wcsite/wp-content/plugins/woo-gutenberg-products-block/src/StoreApi/Schemas/V1/CartItemSchema.php on line 339

To reproduce

Steps to reproduce the behavior:

  1. Enable the full PHP error reporting and enable the WC blocks plugin.
  2. Edit a page
  3. The PHP Notice appears in upper left side of the screen

Expected behavior

No PHP warning notice should be seen.

Environment

WordPress (please complete the following information):

Desktop (please complete the following information):

senadir commented 2 years ago

Thank you for reporting this, can we get a full stack of the error?

NTShop commented 2 years ago

Here it is:

` Call Stack

Time Memory Function Location

1 0.0006 371992 {main}( ) .../post.php:0 2 0.3304 10037424 require( '/var/www/wc/wp-admin/edit-form-blocks.php' ) .../post.php:187 3 0.9486 18023216 do_action( ) .../edit-form-blocks.php:270 4 0.9486 18023592 WP_Hook->do_action( ) .../plugin.php:476 5 0.9486 18023592 WP_Hook->apply_filters( ) .../class-wp-hook.php:331 6 0.9584 18060200 Automattic\WooCommerce\Blocks\BlockTypes\AllProducts->enqueue_editor_assets( ) .../class-wp-hook.php:307 7 0.9584 18060200 Automattic\WooCommerce\Blocks\BlockTypes\AllProducts->enqueue_data( ) .../AbstractBlock.php:98 8 0.9584 18060200 Automattic\WooCommerce\Blocks\BlockTypes\AllProducts->hydrate_from_api( ) .../AllProducts.php:33 9 0.9584 18060200 Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry->hydrate_api_request( ) .../AllProducts.php:40 10 0.9584 18060200 rest_preload_api_request( ) .../AssetDataRegistry.php:317 11 0.9584 18060816 rest_do_request( ) .../rest-api.php:2868 12 0.9584 18060816 WP_REST_Server->dispatch( ) .../rest-api.php:519 13 0.9596 18063016 WP_REST_Server->respond_to_request( ) .../class-wp-rest-server.php:990 14 0.9596 18063016 Automattic\WooCommerce\StoreApi\Routes\V1\Cart->get_response( ) .../class-wp-rest-server.php:1143 15 0.9956 18670400 Automattic\WooCommerce\StoreApi\Routes\V1\Cart->get_response( ) .../AbstractCartRoute.php:80 16 0.9956 18670400 Automattic\WooCommerce\StoreApi\Routes\V1\Cart->get_route_response( ) .../AbstractRoute.php:109 17 0.9956 18670400 Automattic\WooCommerce\StoreApi\Schemas\V1\CartSchema->get_item_response( ) .../Cart.php:50 18 1.0302 18847320 Automattic\WooCommerce\StoreApi\Schemas\V1\CartSchema->get_item_responses_from_schema( ) .../CartSchema.php:352 19 1.0302 18847696 array_map ( ) .../AbstractSchema.php:261 20 1.0302 18848072 Automattic\WooCommerce\StoreApi\Schemas\V1\CartItemSchema->get_item_response( ) .../AbstractSchema.php:261 `

wavvves commented 2 years ago

Hi @NTShop, thank you for reporting this. Unfortunately, I wasn't able to replicate this error using the latest WP, WC, and Blocks version, or the versions you reported, even after trying to force the error (providing an invalid index on CartItemSchema.php:339).

I don't believe this is a bug. key is a required unique identifier for the item within the cart, so it must be set. The expected behavior with full error reporting is to display a warning if such data isn't present, which indicates that something has gone wrong elsewhere (that can range anywhere from a newly introduced bug to incompatible plugins or a corrupted database state).

To help us pinpoint the error cause:

NTShop commented 2 years ago

Hi, at this time I cannot reproduce it again, although previously it was happening for several days each time I went to edit a page. I've updated to the latest WC, WP, and WC Blocks, and the issue remains gone - with or without items in the cart. Very puzzling. Anyway, close this issue, if it pops up for me again I'll try to narrow down the cause and report back.

nielslange commented 2 years ago

Anyway, close this issue, if it pops up for me again I'll try to narrow down the cause and report back.

Thanks for confirming that you also can no longer reproduce this issue, @NTShop. I'll close it now and, as you mentioned, just create a new issue in case the problem occurs again.