Webhook JSON Serializable Error on 'SalesInvoiceItem'

I receive this error while posting a webhook on Sales invoice submission.

{'method_name': 'frappe.integrations.doctype.webhook.webhook.enqueue_webhook', 'log': <function log at 0x7f25f73011e0>, 'retry': 0, 'is_async': True, 'user': 'Administrator', 'kwargs': {'doc': <erpnext.accounts.doctype.sales_invoice.sales_invoice.SalesInvoice object at 0x7f25f75079b0>, 'webhook': {'name': 'Sales Invoice-on_submit', 'condition': None, 'webhook_docevent': 'on_submit', 'webhook_doctype': 'Sales Invoice'}}, 'job_name': 'frappe.integrations.doctype.webhook.webhook.enqueue_webhook', 'event': None, 'method': <function enqueue_webhook at 0x7f25f6d387b8>, 'site': 'erp.**********.com'}
Traceback (most recent call last):
  File "/home/ashffaq/bench/apps/frappe/frappe/utils/background_jobs.py", line 99, in execute_job
method(**kwargs)
  File "/home/ashffaq/bench/apps/frappe/frappe/integrations/doctype/webhook/webhook.py", line 95, in enqueue_webhook
raise e
  File "/home/ashffaq/bench/apps/frappe/frappe/integrations/doctype/webhook/webhook.py", line 85, in enqueue_webhook
r = requests.post(webhook.request_url, data=json.dumps(data), headers=headers, timeout=5)
  File "/usr/lib/python3.6/json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
  File "/usr/lib/python3.6/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.6/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
  File "/usr/lib/python3.6/json/encoder.py", line 180, in default
o.__class__.__name__)
TypeError: Object of type 'SalesInvoiceItem' is not JSON serializable

I use Items(table) as webhook data to send items details.

This was working fine in the previous version of erpnext.

My Current version is
ERPNext: v12.1.8 (version-12)
Frappe Framework: v12.0.18 (version-12)

Any help will be highly appreciated.

Hey @Muhammad_Ashfaq, I’ve made a fix for the error for v12 and v13. It’s up for review now.

2 Likes