Skip to content

Commit

Permalink
Fix regression in .DT_Util.InstanceDict.
Browse files Browse the repository at this point in the history
It broke the acquisition chain of the item it wraps.
  • Loading branch information
Michael Howitz committed Feb 28, 2019
1 parent 3da9dee commit 381b834
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
4 changes: 3 additions & 1 deletion CHANGES.rst
Expand Up @@ -4,7 +4,9 @@ Changelog
3.0b6 (unreleased)
------------------

- Nothing changed yet.
- Fix regression in ``.DT_Util.InstanceDict`` which broke the acquisition
chain of the item it wraps.
(`#38 <https://github.com/zopefoundation/DocumentTemplate/issues/38>`_)


3.0b5 (2018-10-05)
Expand Down
5 changes: 2 additions & 3 deletions src/DocumentTemplate/_DocumentTemplate.py
Expand Up @@ -108,7 +108,6 @@
import types

from Acquisition import aq_base
from Acquisition import aq_inner
from ExtensionClass import Base

from DocumentTemplate.html_quote import html_quote
Expand Down Expand Up @@ -267,7 +266,7 @@ def safe_callable(ob):
return callable(ob)


class InstanceDict(Base):
class InstanceDict(object):
""""""

guarded_getattr = None
Expand Down Expand Up @@ -306,7 +305,7 @@ def __getitem__(self, key):
get = getattr

try:
result = get(aq_inner(self.inst), key)
result = get(self.inst, key)
except AttributeError:
raise KeyError(key)

Expand Down
41 changes: 28 additions & 13 deletions src/DocumentTemplate/tests/test_DocumentTemplate.py
@@ -1,4 +1,18 @@
import unittest
import Acquisition


class Item(Acquisition.Implicit):
"""Class modelling the here necessary parts of OFS.SimpleItem."""

def __init__(self, id):
self.id = id

def __repr__(self):
return '<Item id={0.id!r}>'.format(self)

def method1(self):
pass


class InstanceDictTests(unittest.TestCase):
Expand All @@ -12,22 +26,23 @@ def test_getitem(self):
# https://github.com/zopefoundation/Zope/issues/292

from DocumentTemplate.DT_Util import InstanceDict
import Acquisition

class Item(Acquisition.Implicit):
"""Class modelling the here necessary parts of OFS.SimpleItem."""

def __init__(self, id):
self.id = id

def __repr__(self):
return '<Item id={0.id!r}>'.format(self)

def method1(self):
pass

inst = Item('a').__of__(Item('b'))
i_dict = InstanceDict(inst, {}, getattr)

for element in Acquisition.aq_chain(i_dict['method1'].__self__):
self.assertNotIsInstance(element, InstanceDict)

def test_getitem_2(self):
# It does not break the acquisition chain of stored objects.

from DocumentTemplate.DT_Util import InstanceDict

main = Item('main')
main.sub = Item('sub')
side = Item('side')
side.here = Item('here')

path = side.here.__of__(main)
i_dict = InstanceDict(path, {}, getattr)
self.assertEqual(main.sub, i_dict['sub'])

0 comments on commit 381b834

Please sign in to comment.