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
404 stars 219 forks source link

[REST] Invalid product causes Products API to fatal error #4604

Closed marcusorjames closed 3 years ago

marcusorjames commented 3 years ago

Please provide us with the information requested in this bug report. Without these details, we won't be able to fully evaluate this issue. Bug reports lacking detail, or for any other reason than to report a bug, may be closed without action.

Prerequisites (mark completed items with an [x]):

Describe the bug When using the rest api to fetch products if the database returns an invalid response then it fails the entire response.

Expected behavior Up for discussion. Should a failed product query fail the entire response, or should it handle it and continue

Actual behavior Currently in /packages/woocommerce-blocks/src/StoreApi/Routes/Products.php

    protected function get_route_response( \WP_REST_Request $request ) {
        $response      = new \WP_REST_Response();
        $product_query = new ProductQuery();

        // Only get objects during GET requests.
        if ( \WP_REST_Server::READABLE === $request->get_method() ) {
            $query_results    = $product_query->get_objects( $request );
            $response_objects = [];

            foreach ( $query_results['objects'] as $object ) {
                $data               = rest_ensure_response( $this->schema->get_item_response( $object ) );
                $response_objects[] = $this->prepare_response_for_collection( $data );
            }
.......

The product_query will return an empty array item on a failed product lookup, this then means that in ProductSchema::get_item_response $product->get_id() fatals because $product is not a product.

The problem that I have is that it breaks the entire response and doesn't give any indications of the particular product which is causing the failure. Checking whether $object above is an object and continuing otherwise fixes the issue for now, but it is just brushing it under the rug. I am unsure of the standards in woo commerce in how to handle an invalid data state, but to me failing the entire response is not ideal.

Steps to reproduce the bug (We need to be able to reproduce the bug in order to fix it.) Steps to reproduce the bug:

  1. Put a specific Product data in an invalid state
  2. navigate to wp-json/wc/store/products?per_page=100&catalog_visibility=any&search=&orderby=title&order=asc&_locale=user
  3. Fatal error will trigger

Screenshots If applicable, add screenshots to help explain your problem.

Isolating the problem (mark completed items with an [x]):

WordPress Environment We use the WooCommerce System Status Report to help us evaluate the issue. Without this report we won't be able to fully evaluate this issue.

``` ` ### WordPress Environment ### WordPress address (URL): https://staging.sycal.co.uk Site address (URL): https://staging.sycal.co.uk WC Version: 5.5.2 REST API Version: ✔ 5.5.2 WC Blocks Version: ✔ 5.3.3 Action Scheduler Version: ✔ 3.2.1 WC Admin Version: ✔ 2.4.4 Log Directory Writable: ✔ WP Version: 5.8 WP Multisite: – WP Memory Limit: 4 GB WP Debug Mode: – WP Cron: ✔ Language: en_GB External object cache: – ### Server Environment ### Server Info: Apache PHP Version: 7.3.29 PHP Post Max Size: 128 MB PHP Time Limit: 120 PHP Max Input Vars: 1000 cURL Version: 7.29.0 NSS/3.36 SUHOSIN Installed: – MySQL Version: 5.5.68-MariaDB Max Upload Size: 128 MB Default Timezone is UTC: ✔ fsockopen/cURL: ✔ SoapClient: ✔ DOMDocument: ✔ GZip: ✔ Multibyte String: ✔ Remote Post: ✔ Remote Get: ✔ ### Database ### WC Database Version: 5.5.2 WC Database Prefix: REVIUfJe Total Database Size: 211.05MB Database Data Size: 180.62MB Database Index Size: 30.43MB REVIUfJewoocommerce_sessions: Data: 14.84MB + Index: 0.82MB + Engine MyISAM REVIUfJewoocommerce_api_keys: Data: 0.00MB + Index: 0.01MB + Engine MyISAM REVIUfJewoocommerce_attribute_taxonomies: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewoocommerce_downloadable_product_permissions: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewoocommerce_order_items: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewoocommerce_order_itemmeta: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewoocommerce_tax_rates: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewoocommerce_tax_rate_locations: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewoocommerce_shipping_zones: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewoocommerce_shipping_zone_locations: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewoocommerce_shipping_zone_methods: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewoocommerce_payment_tokens: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewoocommerce_payment_tokenmeta: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewoocommerce_log: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJeactionscheduler_actions: Data: 0.02MB + Index: 0.13MB + Engine InnoDB REVIUfJeactionscheduler_claims: Data: 0.02MB + Index: 0.02MB + Engine InnoDB REVIUfJeactionscheduler_groups: Data: 0.02MB + Index: 0.02MB + Engine InnoDB REVIUfJeactionscheduler_logs: Data: 0.02MB + Index: 0.03MB + Engine InnoDB REVIUfJeaws_cache: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJeaws_index: Data: 22.55MB + Index: 0.00MB + Engine InnoDB REVIUfJecommentmeta: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJecomments: Data: 0.01MB + Index: 0.01MB + Engine MyISAM REVIUfJeeum_logs: Data: 0.14MB + Index: 0.00MB + Engine InnoDB REVIUfJefb3d_pages: Data: 0.02MB + Index: 0.05MB + Engine InnoDB REVIUfJefeedmanager_channel: Data: 0.02MB + Index: 0.03MB + Engine InnoDB REVIUfJefeedmanager_country: Data: 0.02MB + Index: 0.03MB + Engine InnoDB REVIUfJefeedmanager_feed_status: Data: 0.02MB + Index: 0.11MB + Engine InnoDB REVIUfJefeedmanager_field_categories: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJefeedmanager_product_feed: Data: 0.02MB + Index: 0.02MB + Engine InnoDB REVIUfJefeedmanager_product_feedmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB REVIUfJefeedmanager_source: Data: 0.02MB + Index: 0.11MB + Engine InnoDB REVIUfJeformmaker: Data: 0.13MB + Index: 0.00MB + Engine InnoDB REVIUfJeformmaker_backup: Data: 0.50MB + Index: 0.00MB + Engine InnoDB REVIUfJeformmaker_blocked: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJeformmaker_cookies: Data: 1.52MB + Index: 0.00MB + Engine InnoDB REVIUfJeformmaker_display_options: Data: 0.02MB + Index: 0.02MB + Engine InnoDB REVIUfJeformmaker_groups: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJeformmaker_query: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJeformmaker_sessions: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJeformmaker_submits: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJeformmaker_themes: Data: 0.14MB + Index: 0.00MB + Engine InnoDB REVIUfJeformmaker_views: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJelayerslider: Data: 0.03MB + Index: 0.00MB + Engine MyISAM REVIUfJelayerslider_revisions: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJelinks: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJemgmlp_folders: Data: 0.19MB + Index: 0.21MB + Engine MyISAM REVIUfJemy_calendar: Data: 0.02MB + Index: 0.02MB + Engine InnoDB REVIUfJemy_calendar_categories: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJemy_calendar_category_relationships: Data: 0.02MB + Index: 0.02MB + Engine InnoDB REVIUfJemy_calendar_events: Data: 0.02MB + Index: 0.02MB + Engine InnoDB REVIUfJemy_calendar_locations: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJenextend2_image_storage: Data: 0.02MB + Index: 0.02MB + Engine InnoDB REVIUfJenextend2_section_storage: Data: 0.02MB + Index: 0.06MB + Engine InnoDB REVIUfJenextend2_smartslider3_generators: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJenextend2_smartslider3_sliders: Data: 0.06MB + Index: 0.03MB + Engine InnoDB REVIUfJenextend2_smartslider3_sliders_xref: Data: 0.02MB + Index: 0.02MB + Engine InnoDB REVIUfJenextend2_smartslider3_slides: Data: 0.09MB + Index: 0.11MB + Engine InnoDB REVIUfJeoptions: Data: 8.34MB + Index: 1.05MB + Engine MyISAM REVIUfJepostmeta: Data: 102.15MB + Index: 18.21MB + Engine MyISAM REVIUfJeposts: Data: 9.28MB + Index: 2.07MB + Engine MyISAM REVIUfJesg_fblike_popup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJesg_html_popup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJesg_image_popup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJesg_popup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJesg_popup_addons: Data: 0.02MB + Index: 0.02MB + Engine InnoDB REVIUfJesg_popup_addons_connection: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJesg_popup_settings: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJesg_shortCode_popup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJesmush_dir_images: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJesm_sessions: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJetermmeta: Data: 0.29MB + Index: 0.23MB + Engine MyISAM REVIUfJeterms: Data: 0.43MB + Index: 0.78MB + Engine MyISAM REVIUfJeterm_relationships: Data: 0.84MB + Index: 1.49MB + Engine MyISAM REVIUfJeterm_taxonomy: Data: 0.40MB + Index: 0.62MB + Engine MyISAM REVIUfJeudraw_clipart: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJeudraw_clipart_category: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJeudraw_customer_designs: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJeudraw_excel_jobs: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJeudraw_price_matrix: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJeudraw_price_matrix_in_categories: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJeudraw_svg_templates: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJeudraw_templates: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJeudraw_templates_category: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJeudraw_temporary_designdata: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJeusermeta: Data: 1.21MB + Index: 0.04MB + Engine MyISAM REVIUfJeusers: Data: 0.00MB + Index: 0.01MB + Engine MyISAM REVIUfJewc_admin_notes: Data: 0.05MB + Index: 0.00MB + Engine InnoDB REVIUfJewc_admin_note_actions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB REVIUfJewc_category_lookup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJewc_customer_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB REVIUfJewc_download_log: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewc_order_coupon_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB REVIUfJewc_order_product_lookup: Data: 0.02MB + Index: 0.06MB + Engine InnoDB REVIUfJewc_order_stats: Data: 0.02MB + Index: 0.05MB + Engine InnoDB REVIUfJewc_order_tax_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB REVIUfJewc_product_meta_lookup: Data: 1.52MB + Index: 1.25MB + Engine InnoDB REVIUfJewc_reserved_stock: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJewc_tax_rate_classes: Data: 0.02MB + Index: 0.02MB + Engine InnoDB REVIUfJewc_webhooks: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewfBlockedIPLog: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewfBlocks7: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewfConfig: Data: 2.07MB + Index: 0.01MB + Engine MyISAM REVIUfJewfCrawlers: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewfFileChanges: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewfFileMods: Data: 6.77MB + Index: 1.44MB + Engine MyISAM REVIUfJewfHits: Data: 0.59MB + Index: 0.13MB + Engine MyISAM REVIUfJewfHoover: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewfIssues: Data: 0.80MB + Index: 0.12MB + Engine MyISAM REVIUfJewfKnownFileList: Data: 3.48MB + Index: 0.44MB + Engine MyISAM REVIUfJewfLiveTrafficHuman: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewfLocs: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewfLogins: Data: 0.35MB + Index: 0.07MB + Engine MyISAM REVIUfJewfls_2fa_secrets: Data: 0.02MB + Index: 0.02MB + Engine InnoDB REVIUfJewfls_settings: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJewfNotifications: Data: 0.04MB + Index: 0.01MB + Engine MyISAM REVIUfJewfPendingIssues: Data: 0.08MB + Index: 0.02MB + Engine MyISAM REVIUfJewfReverseCache: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewfSNIPCache: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewfStatus: Data: 0.16MB + Index: 0.07MB + Engine MyISAM REVIUfJewfTrafficRates: Data: 0.02MB + Index: 0.00MB + Engine InnoDB REVIUfJewysija_campaign: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewysija_campaign_list: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewysija_custom_field: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewysija_email: Data: 0.03MB + Index: 0.00MB + Engine MyISAM REVIUfJewysija_email_user_stat: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewysija_email_user_url: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewysija_form: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewysija_list: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewysija_queue: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewysija_subscriber_ips: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewysija_url: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewysija_url_mail: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewysija_user: Data: 0.01MB + Index: 0.01MB + Engine MyISAM REVIUfJewysija_user_field: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewysija_user_history: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJewysija_user_list: Data: 0.00MB + Index: 0.00MB + Engine MyISAM REVIUfJeyoast_seo_links: Data: 0.30MB + Index: 0.08MB + Engine MyISAM REVIUfJeyoast_seo_meta: Data: 0.05MB + Index: 0.05MB + Engine MyISAM ### Post Type Counts ### 3d-flip-book: 1 acf-field: 54 acf-field-group: 7 amn_exact-metrics: 1 attachment: 14118 avia_framework_post: 10 custom_css: 3 flamingo_contact: 572 flamingo_inbound: 758 fmemailverification: 1 form-maker: 1 mgmlp_media_folder: 116 nav_menu_item: 41 oembed_cache: 11 page: 94 popup: 3 popup_theme: 6 post: 179 product: 8673 product_enquiry: 59 revision: 10 simple-pay: 7 spucpt: 3 tribe_events: 2 tribe_venue: 1 woo_product_tab: 4 wp_block: 11 wpc-cliparts: 1 wpcf7_contact_form: 16 wpd-config: 9 wysijap: 1 ### Security ### Secure connection (HTTPS): ✔ Hide errors from visitors: ✔ ### Active Plugins (25) ### Advanced Custom Fields: Extended: by ACF Extended – 0.8.8.4 Advanced Custom Fields PRO: by Elliot Condon – 5.9.5 Advanced Woo Search: by ILLID – 2.33 Ajax Search Lite: by Ernest Marcinko – 4.9.3 Better Search Replace: by Delicious Brains – 1.3.4 Contact Form 7: by Takayuki Miyoshi – 5.4.2 Custom Post Type UI: by WebDevStudios – 1.9.2 Flamingo: by Takayuki Miyoshi – 2.2.2 FlippingBook: by FlippingBook Team – 1.3.0 Form Maker: by 10Web Form Builder Team – 1.13.60 Smart Slider 3: by Nextend – 3.5.0.10 Woocommerce New Orders Dashboard Widget: by swadeshswain – 2.2 WooCommerce Product Tabs: by WP Concern – 2.0.6 WooCommerce: by Automattic – 5.5.2 Wordfence Security: by Wordfence – 7.5.4 WordPress Importer: by wordpressdotorg – 0.7 Yoast SEO Premium: by Team Yoast – 5.6 WP Product Feed Manager: by Michel Jongbloed – 1.33.0 WP Rocket: by WP Media – 3.8.8 Smush: by WPMU DEV – 3.8.8 WPB Accordion Menu or Category: by wpbean – 1.4.0 WPS Hide Login: by WPServeur NicolasKulka wpformation – 1.8.5 MailPoet 2: by MailPoet – 2.14 YITH WooCommerce Catalog Mode: by YITH – 2.0.15 YITH Request a Quote for WooCommerce: by YITH – 2.0.0 ### Inactive Plugins (10) ### 404page - your smart custom 404 error page: by Peter Raschendorfer – 11.3.0 Advanced Custom Fields: by Delicious Brains – 5.9.9 Easy Updates Manager: by Easy Updates Manager Team – 9.0.9 Google Analytics Dashboard for WP (GADWP): by ExactMetrics – 6.8.0 Head Meta Data: by Jeff Starr – 20210713 Product Category Dropdowns: by Pektsekye – 1.0.0 Quick Page/Post Redirect Plugin: by anadnet – 5.2.3 Redux: by Redux.io – 4.2.11 Termly | GDPR/CCPA Cookie Consent Banner: by Termly – 3.0.1 UpdraftPlus - Backup/Restore: by UpdraftPlus.Com DavidAnderson – 1.16.59 ### Dropin Plugins (2) ### advanced-cache.php: advanced-cache.php maintenance.php: maintenance.php ### Settings ### API Enabled: ✔ Force SSL: ✔ Currency: GBP (£) Currency Position: left Thousand Separator: , Decimal Separator: . Number of Decimals: 2 Taxonomies: Product Types: external (external) grouped (grouped) simple (simple) variable (variable) Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog) exclude-from-search (exclude-from-search) featured (featured) outofstock (outofstock) rated-1 (rated-1) rated-2 (rated-2) rated-3 (rated-3) rated-4 (rated-4) rated-5 (rated-5) Connected to WooCommerce.com: – ### WC Pages ### Shop base: woocommerce/woocommerce#754 - /shop/ Basket: woocommerce/woocommerce#755 - /basket/ Checkout: woocommerce/woocommerce#756 - /checkout/ My account: woocommerce/woocommerce#757 - /my-account/ Terms and conditions: woocommerce/woocommerce#200 - /terms-conditions/ ### Theme ### Name: sycal Version: 1.0.0 Author URL: https://mage360.com Child Theme: ❌ – If you are modifying WooCommerce on a parent theme that you did not build personally we recommend using a child theme. See: How to create a child theme WooCommerce Support: ✔ ### Templates ### Overrides: sycal/woocommerce/archive-product.php sycal/woocommerce/content-single-product.php sycal/woocommerce/loop/loop-start.php sycal/woocommerce/loop/pagination.php sycal/woocommerce/single-product/meta.php sycal/woocommerce/single-product/price.php sycal/woocommerce/single-product/tabs/tabs.php version 2.4.0 is out of date. The core version is 3.8.0 sycal/woocommerce/single-product.php sycal/woocommerce/taxonomy-product_cat.php version 1.6.4 is out of date. The core version is 4.7.0 Outdated Templates: ❌ Learn how to update ### Action Scheduler ### Complete: 2 Oldest: 2021-08-06 10:14:09 +0000 Newest: 2021-08-06 10:14:09 +0000 Pending: 1 Oldest: 2021-08-06 10:17:31 +0000 Newest: 2021-08-06 10:17:31 +0000 Failed: 1 Oldest: 2021-04-08 08:35:41 +0000 Newest: 2021-04-08 08:35:41 +0000 ### Status report information ### Generated at: 2021-08-06 12:32:35 +01:00 ` ```
juliaamosova commented 3 years ago

Hi @marcusorjames,

Thank you for opening the issue! It requires further feedback from the WooCommerce Core team. I am adding the needs developer feedback label to this issue so that the Core team could take a look.

Please note it may take a few days for them to get to this issue. Thank you for your patience.

vedanshujain commented 3 years ago

Hi, I have transferred this issue to blocks repo which should be the correct team to answer this query.

ralucaStan commented 3 years ago

Hi there @marcusorjames, could you provide some steps for this step Put a specific Product data in an invalid state. I tried different things and I was not able to reproduce.

nerrad commented 3 years ago

Hi @marcusorjames,

We're still waiting additional details to help us with reproducing your issue, since we haven't received a response in a while and there currently isn't anything actionable for us I'm going to go ahead and close this issue. However, if you leave a comment with the additional information we're looking for and we're able to reproduce we will re-open. Thanks for taking the time to leave the original report!