Skip to content

Commit

Permalink
changelog for #46
Browse files Browse the repository at this point in the history
  • Loading branch information
mmerickel committed Sep 6, 2016
1 parent 5acd7b6 commit 4103c58
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Expand Up @@ -5,6 +5,12 @@ unreleased

- Add Python 3.5 support.

- Subtle bugs can occur if you use the transaction manager during a request
in which ``pyramid_tm`` is disabled via an ``activate_hook``. To combat these
types of errors, attempting to access ``request.tm`` will now raise an
``AttributeError`` when ``pyramid_tm`` is inactive.
See https://github.com/Pylons/pyramid_tm/pull/46

Changes
=======

Expand Down
16 changes: 7 additions & 9 deletions pyramid_tm/__init__.py
Expand Up @@ -42,18 +42,16 @@ def tm_tween_factory(handler, registry):
assert attempts > 0

def tm_tween(request):
if 'repoze.tm.active' in request.environ:
if (
# don't handle txn mgmt if repoze.tm is in the WSGI pipeline
'repoze.tm.active' in request.environ or
# pyramid_tm should only be active once
'tm.active' in request.environ or
# check activation hooks
activate is not None and not activate(request)
):
return handler(request)

if 'tm.active' in request.environ:
# only one transaction manager can be active at once
return handler(request)

if activate is not None:
if not activate(request):
return handler(request)

# Set a flag in the environment to enable the `request.tm` property.
request.environ['tm.active'] = True

Expand Down

0 comments on commit 4103c58

Please sign in to comment.