Skip to content

Commit

Permalink
- Fix long-standing bug of setting an int as sortKey return v…
Browse files Browse the repository at this point in the history
…alue

... the transaction manager's ``sortKey`` method must return strings
  • Loading branch information
dataflake committed Jun 11, 2018
1 parent 81610bf commit 23ebba8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Changelog
3.0.3 (unreleased)
------------------

- Nothing changed yet.
- Fix long-standing bug of setting an ``int`` as return value
for the transaction manager's ``sortKey`` method. It must be a string.


3.0.2 (2018-03-16)
Expand Down
6 changes: 3 additions & 3 deletions src/Shared/DC/ZRDB/TM.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ def abort(self, *ignored):
tpc_abort = abort

# Most DA's talking to RDBMS systems do not care about commit order, so
# return the constant 1
_sort_key = 1
# return a constant. Must be a string according to ITransactionManager.
_sort_key = '1'

def sortKey(self, *ignored):
""" The sortKey method is used by the transaction subsystem to have a
Expand All @@ -77,7 +77,7 @@ def sortKey(self, *ignored):
return self._sort_key

def setSortKey(self, sort_key):
self._sort_key = sort_key
self._sort_key = str(sort_key)

class Surrogate:

Expand Down
15 changes: 10 additions & 5 deletions src/Shared/DC/ZRDB/tests/testTM.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ class TestTM(TestCase):

def test_sortKey(self):
tm = TM()
# the default Transaction Manager should have .sortKey() of 1 for
# backward compatibility
self.assertEqual(tm.sortKey(), 1)
# the default Transaction Manager should have .sortKey() of '1' for
# backward compatibility. It must be a string according to the
# ITransactionManager interface.
self.assertEqual(tm.sortKey(), '1')

# but the sortKey() should be adjustable
tm.setSortKey(())
self.assertEqual(tm.sortKey(), ())
tm.setSortKey('2')
self.assertEqual(tm.sortKey(), '2')

tm.setSortKey([])
self.assertEqual(tm.sortKey(), '[]')

def test_suite():
return TestSuite((makeSuite(TestTM),))

0 comments on commit 23ebba8

Please sign in to comment.