Skip to content

Commit

Permalink
Make sure we only compare ints in ZCacheable_getModTime
Browse files Browse the repository at this point in the history
  • Loading branch information
davisagli committed May 9, 2018
1 parent dd61b83 commit edf7fb1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
5 changes: 4 additions & 1 deletion CHANGES.rst
Expand Up @@ -11,7 +11,10 @@ https://github.com/zopefoundation/Zope/blob/4.0a6/CHANGES.rst
4.0b5 (unreleased)
------------------

- Nothing changed yet.
Bugfixes
++++++++

- Fix comparison against non-ints in ZCacheable_getModTime.


4.0b4 (2018-04-23)
Expand Down
6 changes: 4 additions & 2 deletions src/OFS/Cache.py
Expand Up @@ -226,10 +226,12 @@ def ZCacheable_getModTime(self, mtime_func=None):
# Allow mtime_func to influence the mod time.
mtime = mtime_func()
base = aq_base(self)
mtime = max(getattr(base, '_p_mtime', mtime), mtime)
mtime = max(getattr(base, '_p_mtime', mtime) or 0, mtime)
klass = getattr(base, '__class__', None)
if klass:
mtime = max(getattr(klass, '_p_mtime', mtime), mtime)
klass_mtime = getattr(klass, '_p_mtime', mtime)
if isinstance(klass_mtime, int):
mtime = max(klass_mtime, mtime)
return mtime

security.declareProtected(ViewManagementScreensPermission,
Expand Down
14 changes: 14 additions & 0 deletions src/OFS/tests/testCache.py
Expand Up @@ -32,3 +32,17 @@ def test_managersExist(self):

# The parent_cache should still trigger managersExist
self.assertTrue(managersExist(root.child.child_content))


class CacheableTests(unittest.TestCase):

def _getTargetClass(self):
from OFS.Cache import Cacheable
return Cacheable

def _makeOne(self):
return self._getTargetClass()()

def test_ZCacheable_getModTime(self):
ob = self._makeOne()
self.assertEqual(0, ob.ZCacheable_getModTime())
2 changes: 1 addition & 1 deletion tox.ini
Expand Up @@ -9,7 +9,7 @@ commands =
skip_install = true
deps =
coverage
setuptools==33.1.1
setuptools==39.0.1
zc.buildout
setenv =
COVERAGE_FILE=.coverage.{envname}
Expand Down

0 comments on commit edf7fb1

Please sign in to comment.