Skip to content
This repository has been archived by the owner on Mar 22, 2018. It is now read-only.

Commit

Permalink
Merge branch 'testing'
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrasca committed Dec 28, 2015
2 parents 6d130a5 + baf84a8 commit e44f3fe
Show file tree
Hide file tree
Showing 4 changed files with 432 additions and 54 deletions.
1 change: 1 addition & 0 deletions bauble/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ def open(uri, verify=True, show_error_dialogs=False):
from sqlalchemy.pool import NullPool, SingletonThreadPool
from bauble.prefs import testing
poolclass = testing and SingletonThreadPool or NullPool
poolclass = SingletonThreadPool
new_engine = sa.create_engine(uri, echo=SQLALCHEMY_DEBUG,
implicit_returning=False,
poolclass=poolclass)
Expand Down
24 changes: 16 additions & 8 deletions bauble/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,18 +982,23 @@ class GenericEditorPresenter(object):
PROBLEM_DUPLICATE = random()
PROBLEM_EMPTY = random()

def __init__(self, model, view, refresh_view=False):
def __init__(self, model, view, refresh_view=False, session=None):
self.model = model
self.view = view
self.problems = set()
self._dirty = False
try:
self.session = object_session(model)
except UnmappedInstanceError:
if db.Session is not None:
self.session = db.Session()
else:
self.session = None
self.owns_session = False
self.session = session
if session is None:
try:
self.session = object_session(model)
except UnmappedInstanceError:
if db.Session is not None:
self.session = db.Session()
self.owns_session = True
else:
self.session = None

#logger.debug("session, model, view = %s, %s, %s"
# % (self.session, model, view))
if view:
Expand Down Expand Up @@ -1026,6 +1031,9 @@ def commit_changes(self):
self.session.rollback()
self.session.add_all(objs)
raise
finally:
if self.owns_session:
self.session.close()
return True

def __set_model_attr(self, attr, value):
Expand Down

0 comments on commit e44f3fe

Please sign in to comment.