From 6e24757958c797ef411fb87dc147c93e04336f1a Mon Sep 17 00:00:00 2001 From: Chris Rossi Date: Tue, 12 Feb 2013 11:18:48 -0500 Subject: [PATCH] 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". --- .gitignore | 1 + CHANGES.txt | 6 ++++++ pyramid_tm/__init__.py | 3 ++- pyramid_tm/tests.py | 7 ++++--- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 73f10df..bc65f5d 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ dist/ nosetests.xml pyramid_tm/coverage.xml env*/ +venv/ diff --git a/CHANGES.txt b/CHANGES.txt index 950cab9..63e7a78 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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) ---------------- diff --git a/pyramid_tm/__init__.py b/pyramid_tm/__init__.py index a4eabfc..f32cbcc 100644 --- a/pyramid_tm/__init__.py +++ b/pyramid_tm/__init__.py @@ -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(): diff --git a/pyramid_tm/tests.py b/pyramid_tm/tests.py index 6ede661..fdce58e 100644 --- a/pyramid_tm/tests.py +++ b/pyramid_tm/tests.py @@ -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): @@ -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) @@ -229,6 +229,7 @@ class DummyTransaction(TransactionManager): committed = False aborted = False _resources = [] + username = None def __init__(self, doomed=False, retryable=False): self.doomed = doomed @@ -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