[Zodb-checkins] SVN: ZODB/branches/3.8/ Fix for bug 127182: Blobs weren't intended to be subclassable, now we're

Christian Theune ct at gocept.com
Fri Sep 21 02:52:27 EDT 2007


Log message for revision 79782:
  Fix for bug 127182: Blobs weren't intended to be subclassable, now we're
  actively preventing it.
  

Changed:
  U   ZODB/branches/3.8/NEWS.txt
  U   ZODB/branches/3.8/src/ZODB/blob.py
  U   ZODB/branches/3.8/src/ZODB/tests/blob_basic.txt

-=-
Modified: ZODB/branches/3.8/NEWS.txt
===================================================================
--- ZODB/branches/3.8/NEWS.txt	2007-09-21 06:37:25 UTC (rev 79781)
+++ ZODB/branches/3.8/NEWS.txt	2007-09-21 06:52:26 UTC (rev 79782)
@@ -79,6 +79,8 @@
 Blobs
 -----
 
+- (3.8b4) Fixed bug #127182: Blobs were subclassable which was not desired.
+
 - (3.8b3) Fixed bug #126007: tpc_abort had untested code path that was
   broken.
 

Modified: ZODB/branches/3.8/src/ZODB/blob.py
===================================================================
--- ZODB/branches/3.8/src/ZODB/blob.py	2007-09-21 06:37:25 UTC (rev 79781)
+++ ZODB/branches/3.8/src/ZODB/blob.py	2007-09-21 06:52:26 UTC (rev 79782)
@@ -60,14 +60,20 @@
     _p_blob_committed = None    # Filename of the committed data
 
     readers = writers = None
+
+    def __init__(self):
+        # Raise exception if Blobs are getting subclassed
+        # refer to ZODB-Bug No.127182 by Jim Fulton on 2007-07-20
+        if (self.__class__ is not Blob):
+            raise TypeError('Blobs do not support subclassing.')
+        self.__setstate__()
+
     def __setstate__(self, state=None):
-        # We use lists here because it will allow is to add and remove
+        # we use lists here because it will allow us to add and remove
         # atomically
         self.readers = []
         self.writers = []
 
-    __init__ = __setstate__
-
     def __getstate__(self):
         return None
 

Modified: ZODB/branches/3.8/src/ZODB/tests/blob_basic.txt
===================================================================
--- ZODB/branches/3.8/src/ZODB/tests/blob_basic.txt	2007-09-21 06:37:25 UTC (rev 79781)
+++ ZODB/branches/3.8/src/ZODB/tests/blob_basic.txt	2007-09-21 06:52:26 UTC (rev 79782)
@@ -160,3 +160,15 @@
 
     >>> import transaction
     >>> transaction.get().abort()
+
+Subclassing Blobs
+-----------------
+
+Blobs are not subclassable::
+
+    >>> class SubBlob(Blob):
+    ...     pass
+    >>> my_sub_blob = SubBlob()
+    Traceback (most recent call last):
+        ...
+    TypeError: Blobs do not support subclassing.



More information about the Zodb-checkins mailing list