Skip to content

Commit

Permalink
Replace read session write guard with a simpler version
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Krienbühl committed Feb 10, 2015
1 parent c8fe5c6 commit 425b97a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
7 changes: 7 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
Changelog
---------

0.0.2 (unreleased)
~~~~~~~~~~~~~~~~~~

- Replace read session write guard with a simpler version.
[href]

0.0.1 (2015-02-09)
~~~~~~~~~~~~~~~~~~

- Initial release.
[href]
16 changes: 0 additions & 16 deletions libres/context/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,10 @@ def create_session(isolation_level, dsn, engine_config, session_config):
))

if isolation_level == READ_COMMITTED:
# TODO I suspect that I can remove 'guard_flush' in favor of
# 'guard_execute'. They basically do the same thing, but
# 'guard_execute' is simpler and faster (though it will be
# called more often). Not to mention that it also catches
# statements created directly without the help of the orm.
#
# Once all tests are migrated from seantis.reservation it's
# worth a try.
def guard_flush(session, *args):
changelists = [session.dirty, session.deleted, session.new]

# sum up the len of all changelists
if sum(map(len, changelists)):
raise errors.ModifiedReadOnlySession

def guard_execute(conn, clauseelement, multiparams, params):
if isinstance(clauseelement, UpdateBase):
raise errors.ModifiedReadOnlySession

event.listen(session, 'before_flush', guard_flush)
event.listen(session.bind, 'before_execute', guard_execute)

if isolation_level == SERIALIZABLE:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def get_long_description():

setup(
name='libres',
version='0.0.1',
version='0.0.2',
url='http://github.com/seantis/libres/',
license='BSD',
author='Denis Krienbühl',
Expand Down

0 comments on commit 425b97a

Please sign in to comment.