woocommerce / woocommerce

A customizable, open-source ecommerce platform built on WordPress. Build any commerce solution you can imagine.
https://woocommerce.com
9.42k stars 10.77k forks source link

Fatal Error: Call to member function get_error_message() on int when creating a product via legacy api #32348

Closed d2roth closed 2 years ago

d2roth commented 2 years ago

Prerequisites

Describe the bug

When you call /wc-api/v3/products with \\ as the title you get a fatal error.

Expected behavior

The product gets created and you get the newly created product returned.

{
  "product": {
    "title": "\\",
    "id": 458001,
    "created_at": "2022-03-24T21:24:40Z",
    "updated_at": "2022-03-24T21:24:40Z",
    "type": "simple",
    "status": "publish",
    "downloadable": false,
    "virtual": false,
    "permalink": "https:\/\/<<REDACTED>\/product\/product-3\/",
    "sku": "",
    "price": "",
    "regular_price": "",
    "sale_price": null,
    "price_html": "",
    "taxable": true,
    "tax_status": "taxable",
    "tax_class": "",
    "managing_stock": false,
    "stock_quantity": null,
    "in_stock": true,
    "backorders_allowed": false,
    "backordered": false,
    "sold_individually": false,
    "purchaseable": false,
    "featured": false,
    "visible": true,
    "catalog_visibility": "visible",
    "on_sale": false,
    "product_url": "",
    "button_text": "",
    "weight": null,
    "dimensions": {
      "length": "",
      "width": "",
      "height": "",
      "unit": "in"
    },
    "shipping_required": true,
    "shipping_taxable": true,
    "shipping_class": "",
    "shipping_class_id": null,
    "description": "",
    "short_description": "",
    "reviews_allowed": true,
    "average_rating": "0.00",
    "rating_count": 0,
    "related_ids": [
      15732,
      16592,
      156150,
      16758,
      16606
    ],
    "upsell_ids": [],
    "cross_sell_ids": [],
    "parent_id": 0,
    "categories": [
      "Uncategorized"
    ],
    "tags": [],
    "images": [
      {
        "id": 0,
        "created_at": "2022-03-24T21:24:40Z",
        "updated_at": "2022-03-24T21:24:40Z",
        "src": "https:\/\/<<REDACTED>>\/wp-content\/uploads\/woocommerce-placeholder-300x300.png",
        "title": "Placeholder",
        "alt": "Placeholder",
        "position": 0
      }
    ],
    "featured_src": false,
    "attributes": [],
    "downloads": [],
    "download_limit": -1,
    "download_expiry": -1,
    "download_type": "standard",
    "purchase_note": "",
    "total_sales": 0,
    "variations": [],
    "parent": [],
    "grouped_products": [],
    "menu_order": 0
  }
}

Actual behavior

Fatal error: Uncaught Error: Call to a member function get_error_message() on int in /wp-content/plugins/woocommerce/includes/legacy/api/v3/class-wc-api-products.php:330
Stack trace:
#0 /wp-content/plugins/woocommerce/includes/legacy/api/v3/class-wc-api-server.php(371): WC_API_Products->create_product(Array)
#1 /wp-content/plugins/woocommerce/includes/legacy/api/v3/class-wc-api-server.php(222): WC_API_Server->dispatch()
#2 /wp-content/plugins/woocommerce/includes/legacy/class-wc-legacy-api.php(113): WC_API_Server->serve_request()
#3 /wp-includes/class-wp-hook.php(307): WC_Legacy_API->handle_rest_api_requests(Object(WP))
#4 /wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters(NULL, Array)
#5 /wp-includes/plugin.php(522): WP_Hook->do_action(Array)
#6 /wp-includes/class-wp.php(396): in /wp-content/plugins/woocommerce/includes/legacy/api/v3/class-wc-api-products.php on line 330

Steps to reproduce

  1. Enable REST API with Read/Write permissions
  2. Enable Rest Legacy API
  3. Generate API credentials
  4. Send a POST request to /wc-api/v3/products with the following body:
    {
    "product": {
    "title": "\\"
    }
    }

WordPress Environment

`

WordPress Environment

WordPress address (URL): https://<> Site address (URL): https://<> WC Version: 6.3.1 REST API Version: ✔ 6.3.1 WC Blocks Version: ✔ 6.9.0 Action Scheduler Version: ✔ 3.4.0 WC Admin Version: ✔ 3.2.1 Log Directory Writable: ✔ WP Version: 5.9.2 WP Multisite: – WP Memory Limit: 512 MB WP Debug Mode: ✔ WP Cron: ✔ Language: en_CA External object cache: –

Server Environment

Server Info: Apache PHP Version: 7.4.28 PHP Post Max Size: 75 MB PHP Time Limit: 120 PHP Max Input Vars: 1000 cURL Version: 7.61.1 OpenSSL/1.1.1k

SUHOSIN Installed: – MySQL Version: 8.0.28 Max Upload Size: 60 MB Default Timezone is UTC: ✔ fsockopen/cURL: ✔ SoapClient: ✔ DOMDocument: ✔ GZip: ✔ Multibyte String: ✔ Remote Post: ✔ Remote Get: ✔

Database

WC Database Version: 6.2.2 WC Database Prefix: wp_ Total Database Size: 3254.73MB Database Data Size: 2832.47MB Database Index Size: 422.26MB wp_woocommerce_sessions: Data: 0.01MB + Index: 0.00MB + Engine MyISAM wp_woocommerce_api_keys: Data: 0.00MB + Index: 0.01MB + Engine MyISAM wp_woocommerce_attribute_taxonomies: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_woocommerce_downloadable_product_permissions: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_woocommerce_order_items: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_woocommerce_order_itemmeta: Data: 0.02MB + Index: 0.02MB + Engine MyISAM wp_woocommerce_tax_rates: Data: 0.00MB + Index: 0.01MB + Engine MyISAM wp_woocommerce_tax_rate_locations: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_woocommerce_shipping_zones: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_woocommerce_shipping_zone_locations: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_woocommerce_shipping_zone_methods: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_woocommerce_payment_tokens: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_woocommerce_payment_tokenmeta: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_woocommerce_log: Data: 0.00MB + Index: 0.00MB + Engine MyISAM priority_brands: Data: 0.00MB + Index: 0.00MB + Engine MyISAM products_in_each_brand_letter: Data: 0.00MB + Index: 0.00MB + Engine tmp_octopus_to_wc_category_map: Data: 0.02MB + Index: 0.03MB + Engine MyISAM tmp_sku_to_octopus_category: Data: 0.48MB + Index: 0.15MB + Engine MyISAM wp_actionscheduler_actions: Data: 0.82MB + Index: 0.24MB + Engine MyISAM wp_actionscheduler_claims: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_actionscheduler_groups: Data: 0.00MB + Index: 0.01MB + Engine MyISAM wp_actionscheduler_logs: Data: 0.44MB + Index: 0.32MB + Engine MyISAM wp_aws_cache: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_aws_index: Data: 28.60MB + Index: 30.98MB + Engine MyISAM wp_commentmeta: Data: 0.00MB + Index: 0.01MB + Engine MyISAM wp_comments: Data: 0.01MB + Index: 0.01MB + Engine MyISAM wp_commercekit_searches: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_commercekit_waitlist: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_commercekit_wishlist: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_commercekit_wishlist_items: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_e_submissions: Data: 0.00MB + Index: 0.03MB + Engine MyISAM wp_e_submissions_actions_log: Data: 0.00MB + Index: 0.01MB + Engine MyISAM wp_e_submissions_values: Data: 0.01MB + Index: 0.01MB + Engine MyISAM wp_fbv: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_fbv_attachment_folder: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_links: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_mailchimp_carts: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_mailchimp_jobs: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_mo_campaign_log: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_mo_campaign_logmeta: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_mo_conversions: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_mo_email_campaignmeta: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_mo_email_campaigns: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_mo_optin_campaignmeta: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_mo_optin_campaigns: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_options: Data: 29.63MB + Index: 4.22MB + Engine MyISAM wp_postmeta: Data: 430.21MB + Index: 131.17MB + Engine MyISAM wp_posts: Data: 2155.05MB + Index: 12.02MB + Engine MyISAM wp_seraph_accel_queue: Data: 0.00MB + Index: 0.01MB + Engine MyISAM wp_shortpixel_folders: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_shortpixel_meta: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_structuring_markup: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_term_relationships: Data: 7.65MB + Index: 16.25MB + Engine MyISAM wp_term_taxonomy: Data: 0.26MB + Index: 0.36MB + Engine MyISAM wp_termmeta: Data: 0.34MB + Index: 0.31MB + Engine MyISAM wp_terms: Data: 0.24MB + Index: 0.38MB + Engine MyISAM wp_usermeta: Data: 0.28MB + Index: 0.08MB + Engine MyISAM wp_users: Data: 0.01MB + Index: 0.01MB + Engine MyISAM wp_wc_admin_note_actions: Data: 0.01MB + Index: 0.01MB + Engine MyISAM wp_wc_admin_notes: Data: 0.03MB + Index: 0.00MB + Engine MyISAM wp_wc_category_lookup: Data: 0.03MB + Index: 0.05MB + Engine MyISAM wp_wc_customer_lookup: Data: 0.00MB + Index: 0.01MB + Engine MyISAM wp_wc_download_log: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_wc_order_coupon_lookup: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_wc_order_product_lookup: Data: 0.00MB + Index: 0.01MB + Engine MyISAM wp_wc_order_stats: Data: 0.00MB + Index: 0.01MB + Engine MyISAM wp_wc_order_tax_lookup: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_wc_product_attributes_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_product_meta_lookup: Data: 4.19MB + Index: 4.69MB + Engine MyISAM wp_wc_rate_limits: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_wc_reserved_stock: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_wc_tax_rate_classes: Data: 0.00MB + Index: 0.01MB + Engine MyISAM wp_wc_webhooks: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_webarx_event_log: Data: 0.02MB + Index: 0.00MB + Engine MyISAM wp_webarx_firewall_log: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_webarx_logic: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_wps_hit: Data: 13.07MB + Index: 24.34MB + Engine MyISAM wp_wps_index: Data: 91.65MB + Index: 131.08MB + Engine MyISAM wp_wps_key: Data: 2.55MB + Index: 3.37MB + Engine MyISAM wp_wps_object_term: Data: 40.96MB + Index: 52.09MB + Engine MyISAM wp_wps_object_type: Data: 0.00MB + Index: 0.01MB + Engine MyISAM wp_wps_query: Data: 0.96MB + Index: 1.19MB + Engine MyISAM wp_wps_uri: Data: 3.13MB + Index: 0.93MB + Engine MyISAM wp_wps_user_agent: Data: 0.66MB + Index: 0.09MB + Engine MyISAM wp_wsal_metadata: Data: 8.59MB + Index: 5.59MB + Engine MyISAM wp_wsal_occurrences: Data: 12.48MB + Index: 2.08MB + Engine MyISAM

Post Type Counts

attachment: 14633 custom_css: 3 elementor_cf_db: 1969 elementor_font: 2 elementor_library: 74 jet-smart-filters: 33 nav_menu_item: 521 oembed_cache: 92 page: 43 post: 8 product: 10607 product_variation: 2042 psppnotif_workflow: 2 revision: 2602 shop_order: 12 wp_block: 1 wp-rest-api-log: 109195

Security

Secure connection (HTTPS): ✔ Hide errors from visitors: ❌Error messages should not be shown to visitors.

Active Plugins (1)

WooCommerce: by Automattic – 6.3.1

Inactive Plugins (4)

DD Log Legacy Woo API Requests: by – 0.1 DD Remove Uncategorized: by – DD Woo Make Catalog only: by – DD Woo Make Tags Purchasable: by –

Dropin Plugins (2)

advanced-cache.php: advanced-cache.php maintenance.php: maintenance.php

Settings

API Enabled: ✔ Force SSL: – Currency: CAD ($) 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: #265 - /shop/ Cart: #266 - /cart/ Checkout: #267 - /checkout/ My account: #268 - /my-account/ Terms and conditions: #795 - /terms-and-conditions/

Theme

Name: Twenty Twenty-One Version: 1.5 Author URL: https://en-ca.wordpress.org/ 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: –

Action Scheduler

Complete: 2,413 Oldest: 2022-02-24 08:44:06 -0500 Newest: 2022-03-24 17:18:55 -0400

Failed: 39 Oldest: 2021-12-15 00:39:05 -0500 Newest: 2021-12-15 01:05:11 -0500

Pending: 2 Oldest: 2022-03-24 17:19:28 -0400 Newest: 2022-03-24 17:23:09 -0400

Status report information

Generated at: 2022-03-24 17:19:31 -04:00 `

Isolating the problem

vedanshujain commented 2 years ago

hey @d2roth , we are not able to reproduce this issue. With payload

{
  "product": {
    "title": "\\"
  }
}

I am getting proper response like:

{
    "product": {
        "title": "",
        "id": 44137,
        "created_at": "2022-06-29T10:48:31Z",
        "updated_at": "2022-06-29T10:48:31Z",
        "type": "simple",
        "status": "publish",
        "downloadable": false,
        "virtual": false,
        "permalink": "https:\/\/w.test\/product\/44137\/",
        "sku": "",
        "price": "",
        "regular_price": "",
...

Can you verify if this is still happening for you?

github-actions[bot] commented 2 years ago

As a part of this repository's maintenance, this issue is being marked as stale due to inactivity. Please feel free to comment on it in case we missed something.

After 7 days with no activity this issue will be automatically be closed.
github-actions[bot] commented 2 years ago

This issue was closed because it has been 14 days with no activity.