Getting this Error when opening Workflow and and trying to make chages

App Versions

	"frappe": "14.37.1"


Form/Workflow/Travel Request Flow


Syntax error in query:
select "workflow_state", count(*) as count, MAX(docstatus, tabTravel Request EXP) as "tabTravel Request EXP.docstatus, tabTravel Request EXP.modified"
			from "tabTravel Request EXP"
			where coalesce("tabTravel Request EXP"."workflow_state", '') not in ('Draft', 'Approved', 'Rejected', 'Sent for Approval', 'Sent To Travel Desk', 'Trip Extension', 'Booking Confirmed')
			 group by workflow_state
			 order by "tabTravel Request EXP".docstatus asc, "tabTravel Request EXP"."modified" ASC 
Traceback (most recent call last):
  File "apps/frappe/frappe/", line 66, in application
    response = frappe.api.handle()
  File "apps/frappe/frappe/", line 54, in handle
    return frappe.handler.handle()
  File "apps/frappe/frappe/", line 45, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/", line 83, in execute_cmd
    return, **frappe.form_dict)
  File "apps/frappe/frappe/", line 1608, in call
    return fn(*args, **newargs)
  File "apps/frappe/frappe/workflow/doctype/workflow/", line 152, in get_workflow_state_count
    result = frappe.get_all(
  File "apps/frappe/frappe/", line 1925, in get_all
    return get_list(doctype, *args, **kwargs)
  File "apps/frappe/frappe/", line 1897, in get_list
    return frappe.model.db_query.DatabaseQuery(doctype).execute(*args, **kwargs)
  File "apps/frappe/frappe/model/", line 196, in execute
    result = self.build_and_run()
  File "apps/frappe/frappe/model/", line 236, in build_and_run
    return frappe.db.sql(
  File "apps/frappe/frappe/database/postgres/", line 199, in sql
    return super().sql(modify_query(query), modify_values(values), *args, **kwargs)
  File "apps/frappe/frappe/database/", line 219, in sql
    self._cursor.execute(query, values)
psycopg2.errors.SyntaxError: syntax error at or near "Request"
LINE 1: ...ate", count(*) as count, MAX(docstatus, tabTravel Request EX...

Request Data

	"type": "POST",
	"args": {
		"doctype": "Travel Request EXP",
		"workflow_state_field": "workflow_state",
		"states": "[\"Draft\",\"Approved\",\"Rejected\",\"Sent for Approval\",\"Sent To Travel Desk\",\"Trip Extension\",\"Booking Confirmed\"]"
	"headers": {},
	"error_handlers": {},
	"url": "/api/method/frappe.workflow.doctype.workflow.workflow.get_workflow_state_count"

Response Data

	"exception": ""

facing same issue

def get_workflow_state_count(doctype, workflow_state_field, states):
    frappe.has_permission(doctype=doctype, ptype="read", throw=True)
    states = frappe.parse_json(states)
    result = frappe.db.sql("""
        SELECT {0}, COUNT(*) AS count,
            MAX(docstatus) AS max_docstatus,
            MAX(`tab{1}`.creation) AS max_creation
        FROM `tab{1}`
        WHERE COALESCE(`tab{1}`.`{0}`, '') NOT IN %s
        GROUP BY {0}
        ORDER BY max_docstatus ASC, max_creation ASC
    """.format(workflow_state_field, doctype), (states,))
    return [r for r in result if r[0]]

replace this function with the code above