add instance argument to Session constructor

if Session is used only as a wrapper for an existing session instance
its necessary to be able to pass this instance as an argument
This commit is contained in:
c-holtermann 2020-04-02 18:58:52 +02:00
parent 0d0fddcfc5
commit 0da6b851b0

View File

@ -75,7 +75,7 @@ class Session(GnuCashCoreClass):
""" """
def __init__(self, book_uri=None, ignore_lock=False, is_new=False, def __init__(self, book_uri=None, ignore_lock=False, is_new=False,
force_new= False): force_new=False, instance=None):
"""A convenient constructor that allows you to specify a book URI, """A convenient constructor that allows you to specify a book URI,
begin the session, and load the book. begin the session, and load the book.
@ -95,13 +95,15 @@ class Session(GnuCashCoreClass):
ignore_lock is passed to qof_session_begin's argument of the ignore_lock is passed to qof_session_begin's argument of the
same name and is used to break an existing lock on a dataset. same name and is used to break an existing lock on a dataset.
instance argument can be passed if new Session is used as a
wrapper for an existing session instance
This function can raise a GnuCashBackendException. If it does, This function can raise a GnuCashBackendException. If it does,
you don't need to cleanup and call end() and destroy(), that is handled you don't need to cleanup and call end() and destroy(), that is handled
for you, and the exception is raised. for you, and the exception is raised.
""" """
GnuCashCoreClass.__init__(self) GnuCashCoreClass.__init__(self, instance=instance)
if book_uri is not None: if book_uri is not None:
try: try:
self.begin(book_uri, ignore_lock, is_new, force_new) self.begin(book_uri, ignore_lock, is_new, force_new)