Log message for revision 115072:
  Deprecate Products.ZCatalog's current behavior of returning the entire 
catalog content if no query restriction applied. In Zope 2.14 this will result 
in an empty LazyCat to be returned instead.
  

Changed:
  U   Zope/trunk/doc/CHANGES.rst
  U   Zope/trunk/src/Products/ZCatalog/Catalog.py
  U   Zope/trunk/src/Products/ZCatalog/tests/testCatalog.py

-=-
Modified: Zope/trunk/doc/CHANGES.rst
===================================================================
--- Zope/trunk/doc/CHANGES.rst  2010-07-25 10:38:24 UTC (rev 115071)
+++ Zope/trunk/doc/CHANGES.rst  2010-07-25 10:58:18 UTC (rev 115072)
@@ -35,6 +35,10 @@
 Restructuring
 +++++++++++++
 
+- Deprecate Products.ZCatalog's current behavior of returning the entire
+  catalog content if no query restriction applied. In Zope 2.14 this will
+  result in an empty LazyCat to be returned instead.
+
 - Deprecate acquiring the request inside Products.ZCatalog's searchResults
   method if no explicit query argument is given.
 

Modified: Zope/trunk/src/Products/ZCatalog/Catalog.py
===================================================================
--- Zope/trunk/src/Products/ZCatalog/Catalog.py 2010-07-25 10:38:24 UTC (rev 
115071)
+++ Zope/trunk/src/Products/ZCatalog/Catalog.py 2010-07-25 10:58:18 UTC (rev 
115072)
@@ -30,6 +30,7 @@
 from Lazy import LazyMap, LazyCat, LazyValues
 from CatalogBrains import AbstractCatalogBrain, NoBrainer
 from .report import CatalogReport
+from .report import make_key
 
 
 LOG = logging.getLogger('Zope.ZCatalog')
@@ -531,6 +532,12 @@
             # None of the indexes found anything to do with the query
             # We take this to mean that the query was empty (an empty filter)
             # and so we return everything in the catalog
+            warnings.warn('Your query %s produced no query restriction. '
+                          'Currently the entire catalog content is returned. '
+                          'In Zope 2.14 this will result in an empty LazyCat '
+                          'to be returned.' % repr(make_key(self, query)),
+                          DeprecationWarning, stacklevel=3)
+
             if sort_index is None:
                 return LazyMap(self.instantiate, self.data.items(), len(self))
             else:
@@ -775,7 +782,7 @@
                           'keyword arguments is deprecated. In Zope 2.14 the '
                           'query will no longer be automatically taken from '
                           'the acquired request.',
-                          DeprecationWarning, stacklevel=2)
+                          DeprecationWarning, stacklevel=3)
             REQUEST = getattr(self, 'REQUEST', None)
         if isinstance(REQUEST, dict) and not kw:
             # short cut for the best practice

Modified: Zope/trunk/src/Products/ZCatalog/tests/testCatalog.py
===================================================================
--- Zope/trunk/src/Products/ZCatalog/tests/testCatalog.py       2010-07-25 
10:38:24 UTC (rev 115071)
+++ Zope/trunk/src/Products/ZCatalog/tests/testCatalog.py       2010-07-25 
10:58:18 UTC (rev 115072)
@@ -11,12 +11,10 @@
 #
 ##############################################################################
 """ Unittests for Catalog.
-
-$Id$
 """
 
 import unittest
-import Testing
+from Testing.ZopeTestCase.warnhook import WarningsHook
 import Zope2
 Zope2.startup()
 
@@ -78,9 +76,12 @@
 class CatalogBase:
     def setUp(self):
         self._catalog = Catalog()
+        self.warningshook = WarningsHook()
+        self.warningshook.install()
 
     def tearDown(self):
         self._catalog = None
+        self.warningshook.uninstall()
 
 class TestAddDelColumn(CatalogBase,unittest.TestCase):
     def testAdd(self):
@@ -89,7 +90,6 @@
                          'add column failed')
 
     def testAddBad(self):
-        from Products.ZCatalog.Catalog import CatalogError
         self.assertRaises(CatalogError, self._catalog.addColumn, '_id')
 
     def testDel(self):
@@ -199,6 +199,9 @@
 
     def setUp(self):
         from Products.ZCatalog.ZCatalog import ZCatalog
+        self.warningshook = WarningsHook()
+        self.warningshook.install()
+
         self._catalog = ZCatalog('Catalog')
         self._catalog.resolve_path = self._resolve_num
         self._catalog.addIndex('title', 'KeywordIndex')
@@ -212,7 +215,10 @@
             ob = zdummy(x)
             self.d[str(x)] = ob
             self._catalog.catalog_object(ob, str(x))
-        
+
+    def tearDown(self):
+        self.warningshook.uninstall()
+
     def _resolve_num(self, num):
         return self.d[num]
 
@@ -343,6 +349,9 @@
         nums[j] = tmp
 
     def setUp(self):
+        self.warningshook = WarningsHook()
+        self.warningshook.install()
+
         self._catalog = Catalog()
         self._catalog.lexicon = PLexicon('lexicon')
         col1 = FieldIndex('col1')
@@ -378,6 +387,7 @@
 
     def tearDown(self):
         self._catalog = None
+        self.warningshook.uninstall()
 
     def testResultLength(self):
         a = self._catalog()
@@ -595,6 +605,8 @@
     # Test merging results from multiple catalogs
 
     def setUp(self):
+        self.warningshook = WarningsHook()
+        self.warningshook.install()
         self.catalogs = []
         for i in range(3):
             cat = Catalog()
@@ -611,6 +623,9 @@
                 cat.catalogObject(obj, str(i))
             self.catalogs.append(cat)
 
+    def tearDown(self):
+        self.warningshook.uninstall()
+
     def testNoFilterOrSort(self):
         from Products.ZCatalog.Catalog import mergeResults
         results = [cat.searchResults(_merge=0) for cat in self.catalogs]
@@ -690,6 +705,8 @@
 
     def setUp(self):
         from Products.ZCatalog.ZCatalog import ZCatalog
+        self.warningshook = WarningsHook()
+        self.warningshook.install()
         catalog = ZCatalog('catalog')
         catalog.addIndex('id', 'FieldIndex')
         root = Folder('')
@@ -698,10 +715,11 @@
         self.root.catalog = catalog
 
     def tearDown(self):
+        self.warningshook.uninstall()
         noSecurityManager()
         if self._old_flag is not None:
             self._restore_getObject_flag()
-    
+
     def _init_getObject_flag(self, flag):
         from Products.ZCatalog import CatalogBrains
         self._old_flag = CatalogBrains.GETOBJECT_RAISES
@@ -736,7 +754,6 @@
     def test_getObject_restricted_raises_Unauthorized(self):
         # Check that if the object's security does not allow traversal,
         # None is returned
-        from zExceptions import NotFound
         self._init_getObject_flag(True)
         root = self.root
         catalog = root.catalog

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
https://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to