Skip to content

[BUG] TypeError: json.loads(None) on variation image sync — woocommerce_product.images is None for variations #252

Description

@wphamman

Current Behavior

Summary

sync_items.py line 271 calls json.loads(woocommerce_product.images)
unconditionally during variation sync. WooCommerce's variation REST
response uses image (singular object) not images (array), so
.images is None and json.loads raises TypeError.

Stack trace

File "apps/woocommerce_fusion/woocommerce_fusion/tasks/sync_items.py",
line 252, in sync_wc_product_with_erpnext_item
self.update_item(self.woocommerce_product, self.item)
File "apps/woocommerce_fusion/woocommerce_fusion/tasks/sync_items.py",
line 271, in update_item
wc_product_images = json.loads(woocommerce_product.images)
File "/usr/lib/python3.11/json/init.py", line 339, in loads
raise TypeError(...)
TypeError: the JSON object must be str, bytes or bytearray, not NoneType

Reproduction

  1. ERPNext template Item with has_variants=1
  2. Variant Items mapped to WC variation IDs via woocommerce_servers
  3. WC product is type=variable with variations that have their own image
  4. Sync runs → variation pulled via /products/{parent}/variations/{id}
  5. Error logged every cron tick per variant

WC REST shape

GET /wp-json/wc/v3/products/26592/variations/26614 returns:
{"image": {...}, ...} ← singular, not "images"
GET /wp-json/wc/v3/products/26614 returns:
{"images": [...], ...} ← plural array (regular product endpoint)

Suggested fix

Either:
(a) Guard the json.loads — json.loads(woocommerce_product.images or "[]")
(b) Normalize variations: when product type is "variation", wrap
image as images: [image] before update_item
(c) Use the /products/{variation_id} endpoint (returns full schema)

Environment: ERPNext v15, WooCommerce 10.x.

Steps To Reproduce

  1. ERPNext template Item with has_variants=1
  2. Variant Items mapped to WC variation IDs via woocommerce_servers
  3. WC product is type=variable with variations that have their own image
  4. Sync runs → variation pulled via /products/{parent}/variations/{id}
  5. Error logged every cron tick per variant

Expected Behavior

Succesful variable item sync

Anything else?

No response

Environment and Versions

- Frappe Version: v15.96.0 (HEAD)
- ERPNext Version: v15.94.0 (HEAD)
- WooCommerce Fusion: v1.17.2 (HEAD)

Hosting Method

Remote or local Docker Instance

What browsers are you seeing the problem on?

Chrome, N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions