# Buggy code
def set_actual_dates(self):
    self.actual_start_date = None
    self.actual_end_date = None
    if self.get("operations"):
        self.actual_start_date = min(
            [d.actual_start_time for d in self.get("operations") if d.actual_start_time]
        )
        self.actual_end_date = max(
            [d.actual_end_time for d in self.get("operations") if d.actual_end_time]
        )


# Traceback (ValueError)
Traceback (most recent call last):
File "/home/frappe/benches/bench-2017-10-02/apps/frappe/frappe/app.py", line 57, in application
response = frappe.handler.handle()
File "/home/frappe/benches/bench-2017-10-02/apps/frappe/frappe/handler.py", line 22, in handle
data = execute_cmd(cmd)
File "/home/frappe/benches/bench-2017-10-02/apps/frappe/frappe/handler.py", line 53, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File "/home/frappe/benches/bench-2017-10-02/apps/frappe/frappe/__init__.py", line 923, in call
return fn(*args, **newargs)
File "/home/frappe/benches/bench-2017-10-02/apps/frappe/frappe/desk/form/save.py", line 45, in cancel
doc.cancel()
File "/home/frappe/benches/bench-2017-10-02/apps/frappe/frappe/model/document.py", line 752, in cancel
self._cancel()
File "/home/frappe/benches/bench-2017-10-02/apps/frappe/frappe/model/document.py", line 742, in _cancel
self.save()
File "/home/frappe/benches/bench-2017-10-02/apps/frappe/frappe/model/document.py", line 231, in save
return self._save(*args, **kwargs)
File "/home/frappe/benches/bench-2017-10-02/apps/frappe/frappe/model/document.py", line 282, in _save
self.run_post_save_methods()
File "/home/frappe/benches/bench-2017-10-02/apps/frappe/frappe/model/document.py", line 801, in run_post_save_methods
self.run_method("on_cancel")
File "/home/frappe/benches/bench-2017-10-02/apps/frappe/frappe/model/document.py", line 672, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File "/home/frappe/benches/bench-2017-10-02/apps/frappe/frappe/model/document.py", line 893, in composer
return composed(self, method, *args, **kwargs)
File "/home/frappe/benches/bench-2017-10-02/apps/frappe/frappe/model/document.py", line 876, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File "/home/frappe/benches/bench-2017-10-02/apps/frappe/frappe/model/document.py", line 666, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File "/home/frappe/benches/bench-2017-10-02/apps/erpnext/erpnext/projects/doctype/timesheet/timesheet.py", line 100, in on_cancel
self.update_production_order(None)
File "/home/frappe/benches/bench-2017-10-02/apps/erpnext/erpnext/projects/doctype/timesheet/timesheet.py", line 147, in update_production_order
pro.set_actual_dates()
File "/home/frappe/benches/bench-2017-10-02/apps/erpnext/erpnext/manufacturing/doctype/production_order/production_order.py", line 373, in set_actual_dates
self.actual_start_date = min([d.actual_start_time for d in self.get("operations") if d.actual_start_time])
ValueError: min() arg is an empty sequence

# Fixed code
def set_actual_dates(self):
    self.actual_start_date = None
    self.actual_end_date = None
    if self.get("operations"):
        actual_start_dates = [
            d.actual_start_time for d in self.get("operations") if d.actual_start_time
        ]
        if actual_start_dates:
            self.actual_start_date = min(actual_start_dates)

        actual_end_dates = [
            d.actual_end_time for d in self.get("operations") if d.actual_end_time
        ]
        if actual_end_dates:
            self.actual_end_date = max(actual_end_dates)