Skip to content

Commit

Permalink
Merge pull request #7 from zopefoundation/fix_transaction_2
Browse files Browse the repository at this point in the history
Fix compatibility with transaction >= 2.0 and ZODB >= 5.1.
  • Loading branch information
mgedmin committed Nov 23, 2016
2 parents f245224 + 5232a0b commit d123341
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
5 changes: 4 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ CHANGES
4.2.0 (unreleased)
------------------

- Nothing changed yet.
- Update the code to be compatible with ``transaction >= 2.0``.

- Update tests to be compatible with ``ZODB >= 5.1`, thus requiring at least
this version for the tests.


4.1.0 (2016-08-08)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def read(*rnames):
'zope.site>=4.0.0a1',
'zope.testing',
'zope.testrunner',
'ZODB',
'ZODB >= 5.1',
]

setup(
Expand Down
17 changes: 6 additions & 11 deletions src/zope/app/publication/tests/test_zopepublication.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,16 +578,11 @@ def testTransactionAnnotation(self):
(ILocation,), IPhysicallyLocatable)

def get_txn_info():
if hasattr(self.storage, 'iterator'):
# ZODB 3.9
txn_id = self.storage.lastTransaction()
txn = list(self.storage.iterator(txn_id, txn_id))[0]
txn_info = dict(location=txn.extension['location'],
user_name=txn.user,
request_type=txn.extension['request_type'])
else:
# ZODB 3.8
txn_info = self.storage.undoInfo()[0]
txn_id = self.storage.lastTransaction()
txn = list(self.storage.iterator(txn_id, txn_id))[0]
txn_info = dict(location=txn.extension['location'],
user_name=txn.user,
request_type=txn.extension['request_type'])
return txn_info

root = self.db.open().root()
Expand All @@ -601,7 +596,7 @@ def get_txn_info():

from zope.publisher.interfaces import IRequest
expected_path = "/foo/bar"
expected_user = "/ " + self.user.id
expected_user = "/ {}".format(self.user.id).encode('utf-8')
expected_request = IRequest.__module__ + '.' + IRequest.getName()

self.publication.afterCall(self.request, bar)
Expand Down
9 changes: 5 additions & 4 deletions src/zope/app/publication/zopepublication.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ def annotateTransaction(self, txn, request, ob):
it's specific to this particular implementation.
"""
if request.principal is not None:
txn.setUser(request.principal.id)
principal_id = six.text_type(request.principal.id)
txn.setUser(principal_id)

# Work around methods that are usually used for views
bare = removeSecurityProxy(ob)
Expand Down Expand Up @@ -265,7 +266,7 @@ def annotateTransaction(self, txn, request, ob):
def _logErrorWithErrorReportingUtility(self, object, request, exc_info):
# Record the error with the ErrorReportingUtility
self.beginErrorHandlingTransaction(request, object,
'error reporting utility')
u'error reporting utility')
try:
errUtility = zope.component.getUtility(IErrorReportingUtility)

Expand Down Expand Up @@ -343,7 +344,7 @@ def handleException(self, object, request, exc_info, retry_allowed=True):
# We definitely have an Exception
# Set the request body, and abort the current transaction.
self.beginErrorHandlingTransaction(
request, object, 'application error-handling')
request, object, u'application error-handling')
view = None
try:
# We need to get a location, because some template content of
Expand Down Expand Up @@ -425,7 +426,7 @@ def handleException(self, object, request, exc_info, retry_allowed=True):

if adapter is not None:
self.beginErrorHandlingTransaction(
request, object, 'application error-handling side-effect')
request, object, u'application error-handling side-effect')
try:
# Although request is passed in here, it should be
# considered read-only.
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ envlist = coverage-clean, py27, py33, py34, py35, coverage-report

[testenv]
commands =
coverage run setup.py ftest
coverage run -m zope.testrunner --test-path=src --auto-color --auto-progress
setenv =
COVERAGE_FILE=.coverage.{envname}
deps =
coverage
.[test]
zope.testrunner

[testenv:coverage-clean]
deps = coverage
Expand Down

0 comments on commit d123341

Please sign in to comment.