remove __getitem__ (dictionary) access of ZSQLCatalog

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34607 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0339d7a7
......@@ -856,11 +856,19 @@ class Catalog(Folder,
raise
self._last_clear_reserved_time += 1
def __getitem__(self, uid):
def getRecordForUid(self, uid):
"""
Get an object by UID
Note: brain is defined in Z SQL Method object
"""
# this method used to be __getitem__(self, uid) but was found to hurt more
# than it helped: It would be inadvertently called by
# (un)restrictedTraverse and if there was any error in rendering the SQL
# expression or contacting the database, an error different from KeyError
# would be raised, causing confusion.
# It could also have a performance impact for traversals to objects in
# the acquisition context on Zope 2.12 even when it didn't raise a weird
# error.
method = getattr(self, self.sql_getitem_by_uid)
search_result = method(uid = uid)
if len(search_result) > 0:
......
......@@ -89,6 +89,17 @@ class TestSQLCatalog(unittest.TestCase):
self.assertFalse(
self._catalog.isPortalTypeSelected('not_exists', 'Selected'))
def test_getRecordByUid(self):
class MyError(RuntimeError):
pass
# test that our method actually gets called while looking records up by
# uid by raising our own exception
self._catalog.sql_getitem_by_uid = 'z_dummy_lookup_method'
def z_dummy_lookup_method(uid):
raise MyError('foo')
self._catalog.z_dummy_lookup_method = z_dummy_lookup_method
self.assertRaises(MyError, self._catalog.getRecordForUid, 1)
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestSQLCatalog))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment