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

App Versions

{
	"frappe": "14.37.1"
}

Route

Form/Workflow/Travel Request Flow

Traceback

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/app.py", line 66, in application
    response = frappe.api.handle()
  File "apps/frappe/frappe/api.py", line 54, in handle
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 45, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/handler.py", line 83, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "apps/frappe/frappe/__init__.py", line 1608, in call
    return fn(*args, **newargs)
  File "apps/frappe/frappe/workflow/doctype/workflow/workflow.py", line 152, in get_workflow_state_count
    result = frappe.get_all(
  File "apps/frappe/frappe/__init__.py", line 1925, in get_all
    return get_list(doctype, *args, **kwargs)
  File "apps/frappe/frappe/__init__.py", line 1897, in get_list
    return frappe.model.db_query.DatabaseQuery(doctype).execute(*args, **kwargs)
  File "apps/frappe/frappe/model/db_query.py", line 196, in execute
    result = self.build_and_run()
  File "apps/frappe/frappe/model/db_query.py", line 236, in build_and_run
    return frappe.db.sql(
  File "apps/frappe/frappe/database/postgres/database.py", line 199, in sql
    return super().sql(modify_query(query), modify_values(values), *args, **kwargs)
  File "apps/frappe/frappe/database/database.py", 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

@frappe.whitelist()
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