Handle exception when accessing transactions from history-free storage
authorThierry Florac <tflorac@ulthar.net>
Sat, 02 Feb 2019 10:49:24 +0100
changeset 21 ac784d71bb57
parent 20 1f1d69342248
child 22 e38ee68173c9
Handle exception when accessing transactions from history-free storage
src/pyams_zodbbrowser/zmi/views.py
--- a/src/pyams_zodbbrowser/zmi/views.py	Fri Jul 20 13:17:08 2018 +0200
+++ b/src/pyams_zodbbrowser/zmi/views.py	Sat Feb 02 10:49:24 2019 +0100
@@ -15,40 +15,39 @@
 
 # import standard library
 import time
-import transaction
 from html import escape
 
+import transaction
+# import packages
+from BTrees.utils import oid_repr
+from ZODB.POSException import POSKeyError
+from ZODB.utils import p64, tid_repr, u64
+from persistent import Persistent
+from persistent.timestamp import TimeStamp
+from pyramid.httpexceptions import HTTPFound
+from pyramid.view import view_config
+from zope.exceptions.interfaces import UserError
+from zope.interface import Interface, implementer
+
+from pyams_pagelet.pagelet import pagelet_config
 # import interfaces
 from pyams_skin.interfaces import IInnerPage
 from pyams_skin.layer import IPyAMSLayer
-from pyams_zmi.interfaces.menu import IControlPanelMenu
-from pyams_zmi.layer import IAdminLayer
-from pyams_zodbbrowser.interfaces import IValueRenderer, IDatabaseHistory
-
-# import packages
-from BTrees.utils import oid_repr
-from persistent import Persistent
-from persistent.timestamp import TimeStamp
-from pyams_pagelet.pagelet import pagelet_config
 from pyams_skin.viewlet.menu import MenuItem
 from pyams_template.template import template_config
 from pyams_utils.adapter import ContextRequestAdapter
-from pyams_utils.interfaces import PYAMS_APPLICATION_DEFAULT_NAME, PYAMS_APPLICATION_SETTINGS_KEY, \
-    MANAGE_SYSTEM_PERMISSION
+from pyams_utils.interfaces import MANAGE_SYSTEM_PERMISSION, PYAMS_APPLICATION_DEFAULT_NAME, \
+    PYAMS_APPLICATION_SETTINGS_KEY
 from pyams_utils.property import cached_property
 from pyams_viewlet.viewlet import viewlet_config
+from pyams_zmi.interfaces.menu import IControlPanelMenu
+from pyams_zmi.layer import IAdminLayer
+from pyams_zodbbrowser import _
 from pyams_zodbbrowser.diff import compareDictsHTML
 from pyams_zodbbrowser.history import ZodbObjectHistory
+from pyams_zodbbrowser.interfaces import IDatabaseHistory, IValueRenderer
 from pyams_zodbbrowser.state import ZodbObjectState
 from pyams_zodbbrowser.value import TRUNCATIONS, pruneTruncations
-from pyramid.httpexceptions import HTTPFound
-from pyramid.view import view_config
-from ZODB.POSException import POSKeyError
-from ZODB.utils import p64, u64, tid_repr
-from zope.exceptions.interfaces import UserError
-from zope.interface import implementer, Interface
-
-from pyams_zodbbrowser import _
 
 
 def getObjectType(obj):
@@ -533,14 +532,17 @@
                 obj = self.jar.get(record.oid)
                 url = "#zodbbrowser?oid=0x%x&tid=0x%x" % (u64(record.oid),
                                                            utid)
-                objects.append(dict(
-                    oid=u64(record.oid),
-                    path=getObjectPath(obj, d.tid),
-                    oid_repr=oid_repr(record.oid),
-                    class_repr=getObjectType(obj),
-                    url=url,
-                    repr=IValueRenderer(obj).render(d.tid),
-                ))
+                try:
+                    objects.append(dict(
+                        oid=u64(record.oid),
+                        path=getObjectPath(obj, d.tid),
+                        oid_repr=oid_repr(record.oid),
+                        class_repr=getObjectType(obj),
+                        url=url,
+                        repr=IValueRenderer(obj).render(d.tid),
+                    ))
+                except KeyError:  # no history
+                    pass
             if len(objects) == 1:
                 summary = '1 object record'
             else: