Skip to content

Commit

Permalink
Ensure mapped objects are expired following a transaction.commit() when
Browse files Browse the repository at this point in the history
  no database commit was required. Closes #8.
  • Loading branch information
lrowe committed Jun 18, 2014
1 parent a9b17b3 commit a98f951
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Changes
0.7.5 (unreleased)
------------------

* Ensure mapped objects are expired following a ``transaction.commit()`` when
no database commit was required.

See: https://github.com/zopefoundation/zope.sqlalchemy/issues/8

0.7.4 (2014-01-06)
------------------
Expand Down
3 changes: 3 additions & 0 deletions src/zope/sqlalchemy/datamanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ def tpc_begin(self, trans):
def commit(self, trans):
status = _SESSION_STATE[id(self.session)]
if status is not STATUS_INVALIDATED:
session = self.session
if session.expire_on_commit:
session.expire_all()
self._finish('no work')

def tpc_vote(self, trans):
Expand Down
11 changes: 11 additions & 0 deletions src/zope/sqlalchemy/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,17 @@ def testKeepSession(self):
# KeepSession does not rollback on transaction abort
session.rollback()

def testExpireAll(self):
session = Session()
session.add(User(id=1, firstname='udo', lastname='juergens'))
transaction.commit()

session = Session()
instance = session.query(User).get(1)
transaction.commit() # No work, session.close()

self.assertEqual(sa.inspect(instance).expired, True)


class RetryTests(unittest.TestCase):

Expand Down

0 comments on commit a98f951

Please sign in to comment.