Unable to Save Timesheet - Getting 500 Internal Server Error

I am encountering a 500 Internal Server Error when attempting to save a Timesheet entry. The error occurs even though the payload being sent seems to have valid data for the from_time and to_time fields.

Steps to Reproduce:

  1. Open the Timesheet doctype and fill in the required fields, including from_time and to_time.
  2. Click on “Save.”
  3. The system throws a 500 Internal Server Error.

Details of the Payload:

Below is the payload sent during the save operation, which seems correct:

json

Copy code

{
  "docstatus": 0,
  "doctype": "Timesheet",
  "name": "new-timesheet-zhyqgcvbxu",
  "__islocal": 1,
  "__unsaved": 1,
  "owner": "Administrator",
  "naming_series": "TS-.YYYY.-",
  "company": "Redvinca",
  "currency": "INR",
  "exchange_rate": 1,
  "status": "Draft",
  "time_logs": [
    {
      "docstatus": 0,
      "doctype": "Timesheet Detail",
      "name": "new-timesheet-detail-ztwuqbgtie",
      "__islocal": 1,
      "__unsaved": 1,
      "owner": "Administrator",
      "activity_type": "Planning",
      "completed": 0,
      "is_billable": 0,
      "custom_project": "Optimus",
      "parent": "new-timesheet-zhyqgcvbxu",
      "parentfield": "time_logs",
      "parenttype": "Timesheet",
      "idx": 1,
      "description": "Task details",
      "from_time": "2024-10-25T09:16:07.000Z",
      "to_time": "2024-10-25T13:16:07.000Z",
      "hours": 4
    }
  ],
  "total_hours": 4,
  "employee": "HR-EMP-00001",
  "employee_name": "Shweta Panchal"
}

Error in Browser Console:

plaintext

Copy code

POST https://example.com/api/method/frappe.desk.form.save.savedocs 500 (Internal Server Error)
SyntaxError: Unexpected token '<', "<html>..." is not valid JSON

What I’ve Tried:

  1. Custom Script: Ensured the from_time and to_time are not null in the before_save event:

javascript

Copy code

frappe.ui.form.on('Timesheet', {
    before_save: function(frm) {
        frm.doc.time_logs.forEach(function(row) {
            if (!row.from_time || !row.to_time) {
                frappe.msgprint(__('From Time and To Time cannot be empty.'));
            }
        });
    }
});
  1. Restarted Frappe and checked for any misconfigurations.
  2. Checked the browser console for any issues in the payload structure.

Request for Help:

  • Why is this issue occurring when the payload appears valid?
  • Could it be related to MariaDB or Redis services? Would restarting these services resolve the issue without data loss?
  • If anyone has faced similar issues, please guide me on the resolution steps.

@nitin_05 Please check your bench is running or not just run command and check it again

bench start