Commit 18f3e406 authored by Hanno Schlichting's avatar Hanno Schlichting

Deprecate Products.ZCatalog's current behavior of returning the entire catalog...

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.
parent 0cd7d04b
...@@ -35,6 +35,10 @@ Bugs Fixed ...@@ -35,6 +35,10 @@ Bugs Fixed
Restructuring 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 - Deprecate acquiring the request inside Products.ZCatalog's searchResults
method if no explicit query argument is given. method if no explicit query argument is given.
......
...@@ -30,6 +30,7 @@ from BTrees.IOBTree import IOBTree ...@@ -30,6 +30,7 @@ from BTrees.IOBTree import IOBTree
from Lazy import LazyMap, LazyCat, LazyValues from Lazy import LazyMap, LazyCat, LazyValues
from CatalogBrains import AbstractCatalogBrain, NoBrainer from CatalogBrains import AbstractCatalogBrain, NoBrainer
from .report import CatalogReport from .report import CatalogReport
from .report import make_key
LOG = logging.getLogger('Zope.ZCatalog') LOG = logging.getLogger('Zope.ZCatalog')
...@@ -531,6 +532,12 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -531,6 +532,12 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
# None of the indexes found anything to do with the query # None of the indexes found anything to do with the query
# We take this to mean that the query was empty (an empty filter) # We take this to mean that the query was empty (an empty filter)
# and so we return everything in the catalog # 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: if sort_index is None:
return LazyMap(self.instantiate, self.data.items(), len(self)) return LazyMap(self.instantiate, self.data.items(), len(self))
else: else:
...@@ -775,7 +782,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -775,7 +782,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
'keyword arguments is deprecated. In Zope 2.14 the ' 'keyword arguments is deprecated. In Zope 2.14 the '
'query will no longer be automatically taken from ' 'query will no longer be automatically taken from '
'the acquired request.', 'the acquired request.',
DeprecationWarning, stacklevel=2) DeprecationWarning, stacklevel=3)
REQUEST = getattr(self, 'REQUEST', None) REQUEST = getattr(self, 'REQUEST', None)
if isinstance(REQUEST, dict) and not kw: if isinstance(REQUEST, dict) and not kw:
# short cut for the best practice # short cut for the best practice
......
...@@ -11,12 +11,10 @@ ...@@ -11,12 +11,10 @@
# #
############################################################################## ##############################################################################
""" Unittests for Catalog. """ Unittests for Catalog.
$Id$
""" """
import unittest import unittest
import Testing from Testing.ZopeTestCase.warnhook import WarningsHook
import Zope2 import Zope2
Zope2.startup() Zope2.startup()
...@@ -78,9 +76,12 @@ class Folder(OFS_Folder): ...@@ -78,9 +76,12 @@ class Folder(OFS_Folder):
class CatalogBase: class CatalogBase:
def setUp(self): def setUp(self):
self._catalog = Catalog() self._catalog = Catalog()
self.warningshook = WarningsHook()
self.warningshook.install()
def tearDown(self): def tearDown(self):
self._catalog = None self._catalog = None
self.warningshook.uninstall()
class TestAddDelColumn(CatalogBase,unittest.TestCase): class TestAddDelColumn(CatalogBase,unittest.TestCase):
def testAdd(self): def testAdd(self):
...@@ -89,7 +90,6 @@ class TestAddDelColumn(CatalogBase,unittest.TestCase): ...@@ -89,7 +90,6 @@ class TestAddDelColumn(CatalogBase,unittest.TestCase):
'add column failed') 'add column failed')
def testAddBad(self): def testAddBad(self):
from Products.ZCatalog.Catalog import CatalogError
self.assertRaises(CatalogError, self._catalog.addColumn, '_id') self.assertRaises(CatalogError, self._catalog.addColumn, '_id')
def testDel(self): def testDel(self):
...@@ -199,6 +199,9 @@ class TestZCatalog(unittest.TestCase): ...@@ -199,6 +199,9 @@ class TestZCatalog(unittest.TestCase):
def setUp(self): def setUp(self):
from Products.ZCatalog.ZCatalog import ZCatalog from Products.ZCatalog.ZCatalog import ZCatalog
self.warningshook = WarningsHook()
self.warningshook.install()
self._catalog = ZCatalog('Catalog') self._catalog = ZCatalog('Catalog')
self._catalog.resolve_path = self._resolve_num self._catalog.resolve_path = self._resolve_num
self._catalog.addIndex('title', 'KeywordIndex') self._catalog.addIndex('title', 'KeywordIndex')
...@@ -212,7 +215,10 @@ class TestZCatalog(unittest.TestCase): ...@@ -212,7 +215,10 @@ class TestZCatalog(unittest.TestCase):
ob = zdummy(x) ob = zdummy(x)
self.d[str(x)] = ob self.d[str(x)] = ob
self._catalog.catalog_object(ob, str(x)) self._catalog.catalog_object(ob, str(x))
def tearDown(self):
self.warningshook.uninstall()
def _resolve_num(self, num): def _resolve_num(self, num):
return self.d[num] return self.d[num]
...@@ -343,6 +349,9 @@ class TestCatalogObject(unittest.TestCase): ...@@ -343,6 +349,9 @@ class TestCatalogObject(unittest.TestCase):
nums[j] = tmp nums[j] = tmp
def setUp(self): def setUp(self):
self.warningshook = WarningsHook()
self.warningshook.install()
self._catalog = Catalog() self._catalog = Catalog()
self._catalog.lexicon = PLexicon('lexicon') self._catalog.lexicon = PLexicon('lexicon')
col1 = FieldIndex('col1') col1 = FieldIndex('col1')
...@@ -378,6 +387,7 @@ class TestCatalogObject(unittest.TestCase): ...@@ -378,6 +387,7 @@ class TestCatalogObject(unittest.TestCase):
def tearDown(self): def tearDown(self):
self._catalog = None self._catalog = None
self.warningshook.uninstall()
def testResultLength(self): def testResultLength(self):
a = self._catalog() a = self._catalog()
...@@ -595,6 +605,8 @@ class TestMerge(unittest.TestCase): ...@@ -595,6 +605,8 @@ class TestMerge(unittest.TestCase):
# Test merging results from multiple catalogs # Test merging results from multiple catalogs
def setUp(self): def setUp(self):
self.warningshook = WarningsHook()
self.warningshook.install()
self.catalogs = [] self.catalogs = []
for i in range(3): for i in range(3):
cat = Catalog() cat = Catalog()
...@@ -611,6 +623,9 @@ class TestMerge(unittest.TestCase): ...@@ -611,6 +623,9 @@ class TestMerge(unittest.TestCase):
cat.catalogObject(obj, str(i)) cat.catalogObject(obj, str(i))
self.catalogs.append(cat) self.catalogs.append(cat)
def tearDown(self):
self.warningshook.uninstall()
def testNoFilterOrSort(self): def testNoFilterOrSort(self):
from Products.ZCatalog.Catalog import mergeResults from Products.ZCatalog.Catalog import mergeResults
results = [cat.searchResults(_merge=0) for cat in self.catalogs] results = [cat.searchResults(_merge=0) for cat in self.catalogs]
...@@ -690,6 +705,8 @@ class TestZCatalogGetObject(unittest.TestCase): ...@@ -690,6 +705,8 @@ class TestZCatalogGetObject(unittest.TestCase):
def setUp(self): def setUp(self):
from Products.ZCatalog.ZCatalog import ZCatalog from Products.ZCatalog.ZCatalog import ZCatalog
self.warningshook = WarningsHook()
self.warningshook.install()
catalog = ZCatalog('catalog') catalog = ZCatalog('catalog')
catalog.addIndex('id', 'FieldIndex') catalog.addIndex('id', 'FieldIndex')
root = Folder('') root = Folder('')
...@@ -698,10 +715,11 @@ class TestZCatalogGetObject(unittest.TestCase): ...@@ -698,10 +715,11 @@ class TestZCatalogGetObject(unittest.TestCase):
self.root.catalog = catalog self.root.catalog = catalog
def tearDown(self): def tearDown(self):
self.warningshook.uninstall()
noSecurityManager() noSecurityManager()
if self._old_flag is not None: if self._old_flag is not None:
self._restore_getObject_flag() self._restore_getObject_flag()
def _init_getObject_flag(self, flag): def _init_getObject_flag(self, flag):
from Products.ZCatalog import CatalogBrains from Products.ZCatalog import CatalogBrains
self._old_flag = CatalogBrains.GETOBJECT_RAISES self._old_flag = CatalogBrains.GETOBJECT_RAISES
...@@ -736,7 +754,6 @@ class TestZCatalogGetObject(unittest.TestCase): ...@@ -736,7 +754,6 @@ class TestZCatalogGetObject(unittest.TestCase):
def test_getObject_restricted_raises_Unauthorized(self): def test_getObject_restricted_raises_Unauthorized(self):
# Check that if the object's security does not allow traversal, # Check that if the object's security does not allow traversal,
# None is returned # None is returned
from zExceptions import NotFound
self._init_getObject_flag(True) self._init_getObject_flag(True)
root = self.root root = self.root
catalog = root.catalog catalog = root.catalog
......
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