[Erp5-report] r34607 leonardo - in /erp5/trunk/products/ZSQLCatalog: ./ tests/
nobody at svn.erp5.org
nobody at svn.erp5.org
Fri Apr 16 08:00:39 CEST 2010
Author: leonardo
Date: Fri Apr 16 08:00:35 2010
New Revision: 34607
URL: http://svn.erp5.org?rev=34607&view=rev
Log:
remove __getitem__ (dictionary) access of ZSQLCatalog
Modified:
erp5/trunk/products/ZSQLCatalog/SQLCatalog.py
erp5/trunk/products/ZSQLCatalog/tests/testZSQLCatalog.py
Modified: erp5/trunk/products/ZSQLCatalog/SQLCatalog.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/SQLCatalog.py?rev=34607&r1=34606&r2=34607&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/SQLCatalog.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/SQLCatalog.py [utf8] Fri Apr 16 08:00:35 2010
@@ -856,11 +856,19 @@
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:
Modified: erp5/trunk/products/ZSQLCatalog/tests/testZSQLCatalog.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/tests/testZSQLCatalog.py?rev=34607&r1=34606&r2=34607&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/tests/testZSQLCatalog.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/tests/testZSQLCatalog.py [utf8] Fri Apr 16 08:00:35 2010
@@ -89,6 +89,17 @@
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))
More information about the Erp5-report
mailing list