[ZODB-Dev] Re: Weird InvalidObjectReference exception :-(

Chris Withers chrisw@nipltd.com
Mon, 07 Oct 2002 16:53:52 +0100


This is a multi-part message in MIME format.
--------------020400040305000309080009
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Chris Withers wrote:
> 
>> 2002-10-04T16:05:44 PANIC(300)
>> Traceback (innermost last):
>>   Module __main__, line 94, in ?
>>   Module ZODB.Transaction, line 161, in commit
>>   Module ZODB.Transaction, line 222, in commit
>>   Module ZODB.Transaction, line 195, in commit
>>   Module ZODB.Transaction, line 256, in _commit_objects
>>   Module ZODB.Connection, line 387, in commit
>>    - __traceback_info__: (('BTrees._IOBTree', 'IOBucket'), 
>> '\x00\x00\x00\x00\x00
>> \x06\xd6\xc3', '')
>> InvalidObjectReference: Attempt to store an object from a foreign 
>> database conne
>> ction

Right, thanks to some cool help from Matt Kromer (I owe the man beer, and lots 
of it ;-) I now know what's going on. It wasn't the ClientCache code causing the 
problem, but a small change I  made at roughly the same time.

I've attached Matt's patch, is there any reason this shouldn't go onto the 2.6 
branch and CVS HEAD? it really helps with wierdities like this...

Anyway, the traceback I now get is:

    - __traceback_info__: (('BTrees._IOBTree', 'IOBucket'), '\x00\x00\x00\x00\x00
\x06\xd6\xc3', '', '', "My comment")
InvalidObjectReference: ('Attempt to store an object from a foreign database con
nection', <persistent_id object at 016F7440>, <PythonScript at /dateofpublicatio
n used for /path/to/file/object>)

...which actually helped me find a tortuous temporal error in my code (accessing 
a property before it had been added to an object, resulting in a method being 
acquired...)

Pretty please can this patch go in?

cheers,

Chris

--------------020400040305000309080009
Content-Type: text/plain;
 name="coptimizations.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="coptimizations.diff"

--- lib/python/ZODB/coptimizations.c.orig	Mon Oct  7 10:56:42 2002
+++ lib/python/ZODB/coptimizations.c	Mon Oct  7 11:04:59 2002
@@ -118,9 +118,23 @@
       UNLESS (jar=PyObject_GetAttr(object, py__p_jar)) PyErr_Clear();
       if (jar && jar != Py_None && jar != self->jar)
 	{
-	  PyErr_SetString(InvalidObjectReference, 
+          PyObject *errortuple;
+	  errortuple = PyTuple_New(3);
+	  if (errortuple == NULL) {
+	      	PyErr_SetString(InvalidObjectReference, 
 			  "Attempt to store an object from a foreign "
 			  "database connection");
+	  } else {
+		PyTuple_SET_ITEM(errortuple,0,PyString_FromString(
+			  "Attempt to store an object from a foreign "
+			  "database connection"));
+		PyTuple_SET_ITEM(errortuple,1,OBJECT(self));
+		Py_INCREF(self);
+		PyTuple_SET_ITEM(errortuple,2,OBJECT(object));
+		Py_INCREF(object);
+		PyErr_SetObject(InvalidObjectReference, errortuple);
+	  }
+	  Py_XDECREF(errortuple);
 	  return NULL;
 	}
     }

--------------020400040305000309080009--