Therapy session duration not exist ! "Unknown column 'duration' in 'field list"

App Versions

{
	"erpnext": "15.25.0",
	"frappe": "15.28.0",
	"healthcare": "15.0.0",
	"hrms": "15.21.1"
}

Route

Form/Therapy Session/new-therapy-session-ulfhuqbmrl

Traceback

Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 115, in application
    response = frappe.api.handle(request)
  File "apps/frappe/frappe/api/__init__.py", line 49, in handle
    data = endpoint(**arguments)
  File "apps/frappe/frappe/api/v1.py", line 36, in handle_rpc_call
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 49, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/handler.py", line 85, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "apps/frappe/frappe/__init__.py", line 1768, in call
    return fn(*args, **newargs)
  File "apps/frappe/frappe/utils/typing_validations.py", line 31, in wrapper
    return func(*args, **kwargs)
  File "apps/frappe/frappe/client.py", line 227, in save
    doc.save()
  File "apps/frappe/frappe/model/document.py", line 337, in save
    return self._save(*args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 359, in _save
    return self.insert()
  File "apps/frappe/frappe/model/document.py", line 308, in insert
    self.run_method("after_insert")
  File "apps/frappe/frappe/model/document.py", line 962, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1322, in composer
    return composed(self, method, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1304, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "apps/frappe/frappe/model/document.py", line 959, in fn
    return method_object(*args, **kwargs)
  File "apps/healthcare/healthcare/healthcare/doctype/therapy_session/therapy_session.py", line 37, in after_insert
    self.create_nursing_tasks(post_event=False)
  File "apps/healthcare/healthcare/healthcare/doctype/therapy_session/therapy_session.py", line 98, in create_nursing_tasks
    NursingTask.create_nursing_tasks_from_template(
  File "apps/healthcare/healthcare/healthcare/doctype/nursing_task/nursing_task.py", line 80, in create_nursing_tasks_from_template
    NursingTask.create_nursing_tasks(tasks, doc, start_time, post_event)
  File "apps/healthcare/healthcare/healthcare/doctype/nursing_task/nursing_task.py", line 121, in create_nursing_tasks
    frappe.get_doc(options).insert()
  File "apps/frappe/frappe/model/document.py", line 285, in insert
    self.run_method("before_insert")
  File "apps/frappe/frappe/model/document.py", line 962, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1322, in composer
    return composed(self, method, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1304, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "apps/frappe/frappe/model/document.py", line 959, in fn
    return method_object(*args, **kwargs)
  File "apps/healthcare/healthcare/healthcare/doctype/nursing_task/nursing_task.py", line 18, in before_insert
    self.set_task_schedule()
  File "apps/healthcare/healthcare/healthcare/doctype/nursing_task/nursing_task.py", line 65, in set_task_schedule
    self.duration = frappe.db.get_value("Healthcare Activity", self.activity, "duration")
  File "apps/frappe/frappe/database/database.py", line 519, in get_value
    result = self.get_values(
  File "apps/frappe/frappe/database/database.py", line 623, in get_values
    out = self._get_values_from_table(
  File "apps/frappe/frappe/database/database.py", line 896, in _get_values_from_table
    return query.run(as_dict=as_dict, debug=debug, update=update, run=run, pluck=pluck)
  File "apps/frappe/frappe/query_builder/utils.py", line 87, in execute_query
    result = frappe.db.sql(query, params, *args, **kwargs)  # nosemgrep
  File "apps/frappe/frappe/database/database.py", line 234, in sql
    self._cursor.execute(query, values)
  File "env/lib/python3.10/site-packages/pymysql/cursors.py", line 153, in execute
    result = self._query(query)
  File "env/lib/python3.10/site-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 558, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 822, in _read_query_result
    result.read()
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 1200, in read
    first_packet = self.connection._read_packet()
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 772, in _read_packet
    packet.raise_for_error()
  File "env/lib/python3.10/site-packages/pymysql/protocol.py", line 221, in raise_for_error
    err.raise_mysql_exception(self._data)
  File "env/lib/python3.10/site-packages/pymysql/err.py", line 143, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.OperationalError: (1054, "Unknown column 'duration' in 'field list'")

Request Data

{
	"type": "POST",
	"args": {
		"doc": "{\"docstatus\":0,\"doctype\":\"Therapy Session\",\"name\":\"new-therapy-session-ulfhuqbmrl\",\"__islocal\":1,\"__unsaved\":1,\"owner\":\"Administrator\",\"naming_series\":\"HLC-THP-.YYYY.-\",\"company\":\"Al Thaqalyn  Cancer Hospital\",\"location\":\"\",\"start_date\":\"2024-06-17\",\"start_time\":\"14:24:55\",\"exercises\":[],\"codification_table\":[],\"invoiced\":0,\"__run_link_triggers\":1,\"therapy_plan\":\"HLC-THP-2024-00001\",\"patient\":\"WITC000589\",\"therapy_type\":\"FX\",\"duration\":30}"
	},
	"freeze": true,
	"headers": {},
	"error_handlers": {},
	"url": "/api/method/frappe.client.save",
	"request_id": null
}

Response Data

{
	"exception": "pymysql.err.OperationalError: (1054, \"Unknown column 'duration' in 'field list'\")",
	"exc_type": "OperationalError",
	"_exc_source": "healthcare (app)"
}

i found the error and it was strange tbh the problem was at healthcare activity i have one record without duration and this is the source of the bug

IIRC there was a change in the use of start and end points in time in the Framework.

Before, if one of the two fields was missing, it was assumed that it is meant to be the current time (e.g. now()).

Now it throws an error if one of the two is missing, and thus doesn’t presume anything.

1 Like