Skip to content

Commit

Permalink
Merge pull request #5 from zopefoundation/fix-old-style-classes
Browse files Browse the repository at this point in the history
Fix is_broken check with old-style class instances
  • Loading branch information
David Glick committed Sep 17, 2018
2 parents ccbc8f3 + d43aa8c commit b3e31cc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Changes
- Fix tests on Python 2 with ZODB >= 5.4.0, which now uses pickle
protocol 3.

- Fix is_broken check for old-style class instances.


1.0 (2018-02-13)
----------------
Expand Down
24 changes: 24 additions & 0 deletions src/zodbupdate/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class IOtherFactory(zope.interface.Interface):
class Data(object):
pass

class OldData:
pass

class Factory(persistent.Persistent):
pass

Expand All @@ -73,6 +76,8 @@ class OtherFactory(persistent.Persistent):
Factory.__module__ = 'module1'
sys.modules['module1'].Data = Data
Data.__module__ = 'module1'
sys.modules['module1'].OldData = OldData
OldData.__module__ = 'module1'
sys.modules['module1'].interfaces = sys.modules['module1.interfaces']
sys.modules['module1.interfaces'].IFactory = IFactory
IFactory.__module__ = 'module1.interfaces'
Expand Down Expand Up @@ -585,6 +590,25 @@ def test_loaded_renames_override_missing_interfaces(self):
renames = updater.processor.get_rules(implicit=True)
self.assertEqual({}, renames)

def test_old_style_class(self):
factory = self.root['test'] = sys.modules['module1'].Factory()
factory.data = sys.modules['module1'].OldData()
transaction.commit()

self.update()

self.assertIn(
self.storage.load(self.root['test']._p_oid, '')[0],
(
# ZODB < 5.4
'\x80\x02cmodule1\nFactory\nq\x01.'
'\x80\x02}q\x02U\x04dataq\x03(cmodule1\nOldData\nq\x04oq\x05}q\x06bs.'
# ZODB >= 5.4
'\x80\x03cmodule1\nFactory\nq\x01.'
'\x80\x03}q\x02U\x04dataq\x03(cmodule1\nOldData\nq\x04oq\x05}q\x06bs.'
)
)


class Python3Tests(Tests):

Expand Down
2 changes: 1 addition & 1 deletion src/zodbupdate/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
def is_broken(symb):
"""Return true if the given symbol is broken.
"""
return isinstance(symb, six.class_types) and Broken in symb.__mro__
return isinstance(symb, six.class_types) and issubclass(symb, Broken)


if six.PY3:
Expand Down

0 comments on commit b3e31cc

Please sign in to comment.