fix: Rollback, Release locals & Close db connection

When exitting console, rollback and destroy the Frappe connection. This
rollback is added so that rollback_observers are executed in case
methods are run in the console which shouldn't be committed.

For instance, running File.optimize will make changes to the file on
disk but may not update the corresponding data in the DB.
This commit is contained in:
Gavin D'souza 2021-10-14 17:30:51 +05:30
parent 00d137d1cb
commit bc9b3e826b

View file

@ -504,6 +504,12 @@ frappe.db.connect()
])
def _console_cleanup():
# Execute rollback_observers on console close
frappe.db.rollback()
frappe.destroy()
@click.command('console')
@click.option(
'--autoreload',
@ -519,6 +525,9 @@ def console(context, autoreload=False):
frappe.local.lang = frappe.db.get_default("lang")
from IPython.terminal.embed import InteractiveShellEmbed
from atexit import register
register(_console_cleanup)
terminal = InteractiveShellEmbed()
if autoreload: