Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't call setUser on transaction if there is no user logged in. This... #9

Merged
merged 1 commit into from
Feb 12, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ dist/
nosetests.xml
pyramid_tm/coverage.xml
env*/
venv/
6 changes: 6 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Unreleased
----------

- Don't call `setUser` on transaction if there is no user logged in. This could
cause the username set on the transaction to be a strange string: " None".

0.7 (2012-12-30)
----------------

Expand Down
3 changes: 2 additions & 1 deletion pyramid_tm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def tm_tween(request):
if attempts != 1:
request.make_body_seekable()
t = manager.get()
t.setUser(userid, '')
if userid:
t.setUser(userid, '')
t.note(request.path_info)
response = handler(request)
if manager.isDoomed():
Expand Down
7 changes: 4 additions & 3 deletions pyramid_tm/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def setUp(self):
self.request = DummyRequest()
self.response = DummyResponse()
self.registry = DummyRegistry()

def _callFUT(self, handler=None, registry=None, request=None, txn=None):
if handler is None:
def handler(request):
Expand Down Expand Up @@ -114,7 +114,7 @@ class Conflict(TransientError):
def handler(request, count=count):
raise Conflict
self.assertRaises(Conflict, self._callFUT, handler=handler)

def test_handler_isdoomed(self):
txn = DummyTransaction(True)
self._callFUT(txn=txn)
Expand Down Expand Up @@ -229,6 +229,7 @@ class DummyTransaction(TransactionManager):
committed = False
aborted = False
_resources = []
username = None

def __init__(self, doomed=False, retryable=False):
self.doomed = doomed
Expand All @@ -248,7 +249,7 @@ def get(self):
return self

def setUser(self, name, path='/'):
self.username = name
self.username = "%s %s" % (path, name)

def isDoomed(self):
return self.doomed
Expand Down