Repository: frappe/frappe

Issue:
AttributeError: 'SystemSettings' object has no attribute 'enable_password_policy' during `bench restore`
Hello,
I ran `bench update` then tried to restore a backup and this error starts popping up.

It seems it might have come in from 7ccbbce5720bf16d5d3cc94c627e22ef0541e53b


Discussion:
#### Expected Behaviour
Running `bench restore` should restore the database without crashing

#### Actual Behaviour
Running `bench restore` throws `AttributeError: 'SystemSettings' object has no attribute 'enable_password_policy'`. This seems to have been introduced in 7ccbbce

#### Steps to reproduce:
1. Run `bench --site sitename --force restore ~/path/to/backup/file

#### version
erpnext 8.0.24
frappe 8.0.39
Can you please share the full traceback?
Here it is:

```(python)
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/tunde/PycharmProjects/bench/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 79, in <module>
    main()
  File "/home/tunde/PycharmProjects/bench/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 16, in main
    click.Group(commands=commands)(prog_name='bench')
  File "/home/tunde/PycharmProjects/bench/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/tunde/PycharmProjects/bench/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/tunde/PycharmProjects/bench/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/tunde/PycharmProjects/bench/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/tunde/PycharmProjects/bench/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/tunde/PycharmProjects/bench/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/tunde/PycharmProjects/bench/frappe-bench/env/local/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/tunde/PycharmProjects/bench/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 24, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/tunde/PycharmProjects/bench/frappe-bench/apps/frappe/frappe/commands/site.py", line 108, in restore
    force=context.force)
  File "/home/tunde/PycharmProjects/bench/frappe-bench/apps/frappe/frappe/commands/site.py", line 64, in _new_site
    frappe.utils.scheduler.toggle_scheduler(enable_scheduler)
  File "/home/tunde/PycharmProjects/bench/frappe-bench/apps/frappe/frappe/utils/scheduler.py", line 214, in toggle_scheduler
    ss.save()
  File "/home/tunde/PycharmProjects/bench/frappe-bench/apps/frappe/frappe/model/document.py", line 231, in save
    return self._save(*args, **kwargs)
  File "/home/tunde/PycharmProjects/bench/frappe-bench/apps/frappe/frappe/model/document.py", line 264, in _save
    self.run_before_save_methods()
  File "/home/tunde/PycharmProjects/bench/frappe-bench/apps/frappe/frappe/model/document.py", line 772, in run_before_save_methods
    self.run_method("validate")
  File "/home/tunde/PycharmProjects/bench/frappe-bench/apps/frappe/frappe/model/document.py", line 667, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/home/tunde/PycharmProjects/bench/frappe-bench/apps/frappe/frappe/model/document.py", line 892, in composer
    return composed(self, method, *args, **kwargs)
  File "/home/tunde/PycharmProjects/bench/frappe-bench/apps/frappe/frappe/model/document.py", line 875, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/home/tunde/PycharmProjects/bench/frappe-bench/apps/frappe/frappe/model/document.py", line 661, in <lambda>
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
  File "/home/tunde/PycharmProjects/bench/frappe-bench/apps/frappe/frappe/core/doctype/system_settings/system_settings.py", line 15, in validate
    enable_password_policy = cint(self.enable_password_policy) and True or False
AttributeError: 'SystemSettings' object has no attribute 'enable_password_policy'
```
The bug is still present in:

erpnext 8.0.24
frappe 8.0.40
@nabinhait, 
Have you been able to reproduce this issue? 

Resolving patch:
diff --git a/frappe/utils/scheduler.py b/frappe/utils/scheduler.py
--- a/frappe/utils/scheduler.py
+++ b/frappe/utils/scheduler.py
@@ -207,11 +207,7 @@ def is_scheduler_disabled():
 	return not frappe.utils.cint(frappe.db.get_single_value("System Settings", "enable_scheduler"))
 
 def toggle_scheduler(enable):
-	ss = frappe.get_doc("System Settings")
-	ss.enable_scheduler = 1 if enable else 0
-	ss.flags.ignore_mandatory = True
-	ss.flags.ignore_permissions = True
-	ss.save()
+	frappe.db.set_value("System Settings", None, "enable_scheduler", 1 if enable else 0)
 
 def enable_scheduler():
 	toggle_scheduler(True)


Test patch: