[Zope-Checkins] CVS: Zope/lib/python/Products/ZCatalog - CatalogBrains.py:

Casey Duncan casey at zope.com
Tue Mar 23 14:57:54 EST 2004

Update of /cvs-repository/Zope/lib/python/Products/ZCatalog
In directory cvs.zope.org:/tmp/cvs-serv24183

Modified Files:
      Tag: casey-brains-eat-conflicts-branch
Log Message:
Reduce catalog brains tendancy to eat conflict errors which could result in random loss of valid results in high-concurrency situations. This problem is especially bad for applications (like CMF) that rely on catalog results as a way to get a list of objects to act on. Specific refactorings:

- CatalogBrains getPath() and getObject() calls will propagate ConflictErrors

- getObject() better respects security settings on search results and returns
  None for results that cannot be traversed.

- CatalogBrains now have their own unit tests

- Tone down the Catalog range tests from 10,000 ranges to 1,000 ranges. The
  former took way too long. Note: this test uses random ranges which is
  dubious since it's not really repeatable, I'm punting on fixing that now...

=== Zope/lib/python/Products/ZCatalog/CatalogBrains.py 1.8 => ===
--- Zope/lib/python/Products/ZCatalog/CatalogBrains.py:1.8	Mon Sep 30 14:05:40 2002
+++ Zope/lib/python/Products/ZCatalog/CatalogBrains.py	Tue Mar 23 14:57:23 2004
@@ -30,25 +30,24 @@
         return self.aq_parent.getpath(self.data_record_id_)
     def getURL(self, relative=0):
-        """Try to generate a URL for this record"""
-        try:
-            return self.REQUEST.physicalPathToURL(self.getPath(), relative)
-        except:
-            return self.getPath()
+        """Generate a URL for this record"""
+        # XXX The previous implementation attempted to eat errors coming from
+        #     REQUEST.physicalPathToURL. Unfortunately it also ate 
+        #     ConflictErrors (from getPath), which is bad. Staring at the 
+        #     relevent code in HTTPRequest.py it's unclear to me what could be 
+        #     raised by it so I'm removing the exception handling here all 
+        #     together. If undesired exceptions get raised somehow we should 
+        #     avoid bare except band-aids and find a real solution.
+        return self.REQUEST.physicalPathToURL(self.getPath(), relative)
     def getObject(self, REQUEST=None):
-        """Try to return the object for this record"""
-        try:
-            obj = self.aq_parent.unrestrictedTraverse(self.getPath())
-            if not obj:
-                if REQUEST is None:
-                    REQUEST = self.REQUEST
-                obj = self.aq_parent.resolve_url(self.getPath(), REQUEST)
-            return obj
-        except:
-            zLOG.LOG('CatalogBrains', zLOG.INFO, 'getObject raised an error',
-                     error=sys.exc_info())
-            pass
+        """Return the object for this record
+        Will return None if the object cannot be found via its cataloged path
+        (i.e., it was deleted or moved without recataloging), or if the user is
+        not authorized to access an object along the path.
+        """
+        return self.aq_parent.restrictedTraverse(self.getPath(), None)
     def getRID(self):
         """Return the record ID for this object."""

More information about the Zope-Checkins mailing list