Re: [Zope] Need some help to get rid of an InvalidObjectReference exception

2008-08-23 Thread Dieter Maurer
chaouche yacine wrote at 2008-8-20 01:52 -0700:
 ...
How do I know to which ZODB a specific object belongs to ?

A persistent object has the attribute _p_jar.
This attribute is None when the object was not loaded from
the ZODB and otherwise, it is the ZODB connection which has loaded
it.

A ZODB connection has the method db() (or similar) which returns
the ZODB database this connection belongs to.

More details in the source (ZODB.DB and ZODB.Connection).



-- 
Dieter
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Need some help to get rid of an InvalidObjectReference exception

2008-08-23 Thread Dieter Maurer
chaouche yacine wrote at 2008-8-20 05:21 -0700:
 ...
Ok here's how I did to finally fix it :

* create a new Transient Object Container (sessionTOC) at root
* create a new Session Data Manager (sessionDM), with the following settings :
** Id : sessionDM
** Transient Object Container Path : /sessionTOC
** Place SESSION in REQUEST object as : ZODBSESSION

Now I can put ZODB objects in ZODBSESSION using something like : 

context.REQUEST.ZODBSESSION.set(object,o)

Thanks to all of you for your precious help.

I already know that you have abandoned this approach already (good).

What you did: you have put the sessions into the main ZODB storage.
The ZODB can have the same persistent object at different places
in the persistent graph. *HOWEVER* Zope usually does not like
its (what I call site building) objects to be at different places.

This means, that templates and scripts behave quite differently
(their container changes and maybe their context) dependent
on the location from which they have been fetched.


Do not put templates/scripts at secondary positions in the ZODB
(use just a single primary position). Use instead references (e.g. paths)
to the templates/scripts and resolve the references to the real objects.



-- 
Dieter
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Need some help to get rid of an InvalidObjectReference exception

2008-08-21 Thread chaouche yacine
  Yes this could be dangerous, but in my case these volatile
 attributes need not to be in the cache for a very long time,
 it's just a matter of 3 or 4 clicks in about half a
 dozen of minutes. But yeah, I'll really have to be
 careful about that, or to recreate them if they're gone
 (hence the setattr and getattr to make sure there's
 something in self._v_something and create one  if
 there's not)

Ok, I changed my mind again ^_^. Volatile attributes are shared across multiple 
sessions, which is not acceptable for my application.

So here's what I cam up with :
* 1 : Do not store references to a ZODBish object into a non ZODBish object
* And 2 : just pass the context as a parameter to all the non-ZODBish methods 
that need it. I Tried to avoid this in the first place (hence storing it as an 
attribute), but putting them in the session broke everything.

Cheers.




  
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Need some help to get rid of an InvalidObjectReference exception

2008-08-20 Thread chaouche yacine
 Need some help to get rid of an InvalidObjectReference
 exception
 In my zope product, when I try to put some specific
 object in the session, I get this :
 
 2008-08-18T14:51:02 ERROR(200) SiteError
 http://www.afdas.com:8091/noyauafdas/tests/testAdresses
 Traceback (most recent call last):
   File
 /opt/Zope-2.7/lib/python/ZPublisher/Publish.py,
 line 107, in publish
 transactions_manager.commit()
   File
 /opt/Zope-2.7/lib/python/Zope/App/startup.py,
 line 222, in commit
 get_transaction().commit()
   File
 /opt/Zope-2.7/lib/python/ZODB/Transaction.py,
 line 241, in commit
 ncommitted += self._commit_objects(objects)
   File
 /opt/Zope-2.7/lib/python/ZODB/Transaction.py,
 line 356, in _commit_objects
 jar.commit(o, self)
   File
 /opt/Zope-2.7/lib/python/ZODB/Connection.py,
 line 452, in commit
 dump(state)
 InvalidObjectReference: Attempt to store an object from
 a foreign database connection
 
 A given persistent object can only be in one (ZODB-)
 database, not in several
 databases at the same time.
 
 You must copy the persistent object, when you want it to be
 stored
 (also) in another (ZODB-) database.
 
 You can use the _getCopy(destination) method to
 create such
 a copy. _getCopy is defined by
 OFS.CopySupport.CopySource inherited
 by most Zope objects.
 
 
 
 -- 
 Dieter

Well if it is the case, I didn't do it on purpose because I didn't use any 
specific ZODB code to copy objects on different ZODBs. 

How do I know to which ZODB a specific object belongs to ?




  
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Need some help to get rid of an InvalidObjectReference exception

2008-08-20 Thread chaouche yacine



--- On Tue, 8/19/08, Dieter Maurer [EMAIL PROTECTED] wrote:

 From: Dieter Maurer [EMAIL PROTECTED]
 Subject: Re: [Zope] Need some help to get rid of an InvalidObjectReference 
 exception
 To: [EMAIL PROTECTED]
 Cc: zope@zope.org
 Date: Tuesday, August 19, 2008, 11:16 AM
 chaouche yacine wrote at 2008-8-18 09:50 -0700:
 Need some help to get rid of an InvalidObjectReference
 exception
 In my zope product, when I try to put some specific
 object in the session, I get this :
 
 2008-08-18T14:51:02 ERROR(200) SiteError
 http://www.afdas.com:8091/noyauafdas/tests/testAdresses
 Traceback (most recent call last):
   File
 /opt/Zope-2.7/lib/python/ZPublisher/Publish.py,
 line 107, in publish
 transactions_manager.commit()
   File
 /opt/Zope-2.7/lib/python/Zope/App/startup.py,
 line 222, in commit
 get_transaction().commit()
   File
 /opt/Zope-2.7/lib/python/ZODB/Transaction.py,
 line 241, in commit
 ncommitted += self._commit_objects(objects)
   File
 /opt/Zope-2.7/lib/python/ZODB/Transaction.py,
 line 356, in _commit_objects
 jar.commit(o, self)
   File
 /opt/Zope-2.7/lib/python/ZODB/Connection.py,
 line 452, in commit
 dump(state)
 InvalidObjectReference: Attempt to store an object from
 a foreign database connection
 
 A given persistent object can only be in one (ZODB-)
 database, not in several
 databases at the same time.
 
 You must copy the persistent object, when you want it to be
 stored
 (also) in another (ZODB-) database.
 
 You can use the _getCopy(destination) method to
 create such
 a copy. _getCopy is defined by
 OFS.CopySupport.CopySource inherited
 by most Zope objects.
 
 
 
 -- 
 Dieter

I narrowed the code to what is necessary to fire this exception, and here is 
the tarball for those who want to test it live 
http://yacinechaouche.googlepages.com/InvalidObjectReferenceExample.tgz

This is the directory contents :

+ InvalidObjectReferenceExample 
\_ __init__.py
\_ NonZODBObject.py
\_+ zmi
  \_ ZODBLivingObjectAddForm.pt
\_ ZODBLivingObject.py


NonZODBObject.py

class NonZODBObject:

Hello, i do not live in the ZODB


def __init__(self,p_context):


# This is the evil line. 
self.context = p_context

===
ZODBLivingObject.py
===
from OFS.SimpleItem import SimpleItem
from NonZODBObject import NonZODBObject


class ZODBLivingObject(SimpleItem) :

Hello, I live in the ZODB.

meta_type = ZODBish
def __init__(self):


self.id = ZODBish
self.title = ZODBish

def breakEverything(self):


nonZODBish = NonZODBObject(self)
# This line breaks everything.
self.REQUEST.SESSION.set('breakish',nonZODBish)
# This can be seen in the console if runzope
print it's me,nonZODBish.context
return nonZODBish.context



__init__.py contains the code necessary to create a ZODBish in the ZODB through 
the ZMI
zmi contains the form that adds a ZODBish through the ZMI

As you see, I do not intentionally copy objects from one ZODB to another... 
Except maybe if the session has a separate storage and that this breaks 
everything. But then, I could not even use the _getCopy method because 
nonZODBish do not have a _p_jar attribute.

Any help or comment would be appreciated .


  
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Need some help to get rid of an InvalidObjectReference exception

2008-08-20 Thread chaouche yacine
--- On Wed, 8/20/08, chaouche yacine [EMAIL PROTECTED] wrote:

 From: chaouche yacine [EMAIL PROTECTED]
 Subject: Re: [Zope] Need some help to get rid of an InvalidObjectReference 
 exception
 To: Dieter Maurer [EMAIL PROTECTED]
 Cc: zope@zope.org
 Date: Wednesday, August 20, 2008, 3:22 AM
 --- On Tue, 8/19/08, Dieter Maurer
 [EMAIL PROTECTED] wrote:
 
  From: Dieter Maurer [EMAIL PROTECTED]
  Subject: Re: [Zope] Need some help to get rid of an
 InvalidObjectReference exception
  To: [EMAIL PROTECTED]
  Cc: zope@zope.org
  Date: Tuesday, August 19, 2008, 11:16 AM
  chaouche yacine wrote at 2008-8-18 09:50 -0700:
  Need some help to get rid of an
 InvalidObjectReference
  exception
  In my zope product, when I try to put some
 specific
  object in the session, I get this :
  
  2008-08-18T14:51:02 ERROR(200) SiteError
 
 http://www.afdas.com:8091/noyauafdas/tests/testAdresses
  Traceback (most recent call last):
File
 
 /opt/Zope-2.7/lib/python/ZPublisher/Publish.py,
  line 107, in publish
  transactions_manager.commit()
File
 
 /opt/Zope-2.7/lib/python/Zope/App/startup.py,
  line 222, in commit
  get_transaction().commit()
File
 
 /opt/Zope-2.7/lib/python/ZODB/Transaction.py,
  line 241, in commit
  ncommitted += self._commit_objects(objects)
File
 
 /opt/Zope-2.7/lib/python/ZODB/Transaction.py,
  line 356, in _commit_objects
  jar.commit(o, self)
File
 
 /opt/Zope-2.7/lib/python/ZODB/Connection.py,
  line 452, in commit
  dump(state)
  InvalidObjectReference: Attempt to store an object
 from
  a foreign database connection
  
  A given persistent object can only be in one (ZODB-)
  database, not in several
  databases at the same time.
  
  You must copy the persistent object, when you want it
 to be
  stored
  (also) in another (ZODB-) database.
  
  You can use the _getCopy(destination)
 method to
  create such
  a copy. _getCopy is defined by
  OFS.CopySupport.CopySource inherited
  by most Zope objects.
  
  
  
  -- 
  Dieter
 
 I narrowed the code to what is necessary to fire this
 exception, and here is the tarball for those who want to
 test it live
 http://yacinechaouche.googlepages.com/InvalidObjectReferenceExample.tgz
 
 This is the directory contents :
 
 + InvalidObjectReferenceExample 
 \_ __init__.py
 \_ NonZODBObject.py
 \_+ zmi
   \_ ZODBLivingObjectAddForm.pt
 \_ ZODBLivingObject.py
 
 
 NonZODBObject.py
 
 class NonZODBObject:
 
 Hello, i do not live in the ZODB
 
 
 def __init__(self,p_context):
 
 
   # This is the evil line. 
 self.context = p_context
 
 ===
 ZODBLivingObject.py
 ===
 from OFS.SimpleItem import SimpleItem
 from NonZODBObject import NonZODBObject
 
 
 class ZODBLivingObject(SimpleItem) :
 
 Hello, I live in the ZODB.
 
 meta_type = ZODBish
 def __init__(self):
 
 
 self.id = ZODBish
 self.title = ZODBish
 
 def breakEverything(self):
 
 
 nonZODBish = NonZODBObject(self)
 # This line breaks everything.

 self.REQUEST.SESSION.set('breakish',nonZODBish)
 # This can be seen in the console if runzope
 print it's me,nonZODBish.context
 return nonZODBish.context
 
 
 
 __init__.py contains the code necessary to create a ZODBish
 in the ZODB through the ZMI
 zmi contains the form that adds a ZODBish through the ZMI
 
 As you see, I do not intentionally copy objects from one
 ZODB to another... Except maybe if the session has a
 separate storage and that this breaks everything. But then,
 I could not even use the _getCopy method because nonZODBish
 do not have a _p_jar attribute.
 
 Any help or comment would be appreciated .


No, I got it all wrong, it is much simpler than that : I cannot put any ZODB 
living object into the session, be it a python script, a page template, 
anything... this is not product specific.

So the question is now : is there another way to put some ZODB objects in the 
session for future use ? because there is no reason to create the same object 
twice or thrice in my product so I want it to stay in the session.

Thanks.








  
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Need some help to get rid of an InvalidObjectReference exception

2008-08-20 Thread Andrew Milton
+---[ chaouche yacine ]--
|
|  As you see, I do not intentionally copy objects from one
|  ZODB to another... Except maybe if the session has a
|  separate storage and that this breaks everything. But then,
|  I could not even use the _getCopy method because nonZODBish
|  do not have a _p_jar attribute.

SESSION does use its own store.

-- 
Andrew Milton
[EMAIL PROTECTED]
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Need some help to get rid of an InvalidObjectReference exception

2008-08-20 Thread chaouche yacine



--- On Wed, 8/20/08, chaouche yacine [EMAIL PROTECTED] wrote:
 So the question is now : is there another way to put some
 ZODB objects in the session for future use ? because there
 is no reason to create the same object twice or thrice in my
 product so I want it to stay in the session.
 
 Thanks.

Maybe I should try this : 
http://www.zope.org/Documentation/Books/ZopeBook/2_6Edition/Sessions.stx#3-126


  
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Need some help to get rid of an InvalidObjectReference exception

2008-08-20 Thread chaouche yacine
--- On Wed, 8/20/08, chaouche yacine [EMAIL PROTECTED] wrote:

 From: chaouche yacine [EMAIL PROTECTED]
 Subject: Re: [Zope] Need some help to get rid of an InvalidObjectReference 
 exception
 To: Dieter Maurer [EMAIL PROTECTED]
 Cc: zope@zope.org
 Date: Wednesday, August 20, 2008, 5:12 AM
 --- On Wed, 8/20/08, chaouche yacine
 [EMAIL PROTECTED] wrote:
  So the question is now : is there another way to put
 some
  ZODB objects in the session for future use ? because
 there
  is no reason to create the same object twice or thrice
 in my
  product so I want it to stay in the session.
  
  Thanks.
 
 Maybe I should try this :
 http://www.zope.org/Documentation/Books/ZopeBook/2_6Edition/Sessions.stx#3-126
 
 
   
 ___
 Zope maillist  -  Zope@zope.org
 http://mail.zope.org/mailman/listinfo/zope
 **   No cross posts or HTML encoding!  **
 (Related lists - 
  http://mail.zope.org/mailman/listinfo/zope-announce
  http://mail.zope.org/mailman/listinfo/zope-dev )


Ok here's how I did to finally fix it :

* create a new Transient Object Container (sessionTOC) at root
* create a new Session Data Manager (sessionDM), with the following settings :
** Id : sessionDM
** Transient Object Container Path : /sessionTOC
** Place SESSION in REQUEST object as : ZODBSESSION

Now I can put ZODB objects in ZODBSESSION using something like : 

context.REQUEST.ZODBSESSION.set(object,o)

Thanks to all of you for your precious help.











  
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Need some help to get rid of an InvalidObjectReference exception

2008-08-20 Thread Andrew Milton
+---[ chaouche yacine ]--
|
| Ok here's how I did to finally fix it :
| 
| * create a new Transient Object Container (sessionTOC) at root
| * create a new Session Data Manager (sessionDM), with the following settings :
| ** Id : sessionDM
| ** Transient Object Container Path : /sessionTOC
| ** Place SESSION in REQUEST object as : ZODBSESSION
| 
| Now I can put ZODB objects in ZODBSESSION using something like : 
| 
| context.REQUEST.ZODBSESSION.set(object,o)
| 
| Thanks to all of you for your precious help.

Your main ZODB will grow everytime you add or remove something in
ZODBSESSION, you're essentially storing the same object twice in your
ZODB.

-- 
Andrew Milton
[EMAIL PROTECTED]
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Need some help to get rid of an InvalidObjectReference exception

2008-08-20 Thread chaouche yacine



--- On Wed, 8/20/08, Andrew Milton [EMAIL PROTECTED] wrote:

 From: Andrew Milton [EMAIL PROTECTED]
 Subject: Re: [Zope] Need some help to get rid of an InvalidObjectReference 
 exception
 To: chaouche yacine [EMAIL PROTECTED]
 Cc: zope@zope.org
 Date: Wednesday, August 20, 2008, 5:27 AM
 +---[ chaouche yacine ]--
 |
 | Ok here's how I did to finally fix it :
 | 
 | * create a new Transient Object Container (sessionTOC) at
 root
 | * create a new Session Data Manager (sessionDM), with the
 following settings :
 | ** Id : sessionDM
 | ** Transient Object Container Path : /sessionTOC
 | ** Place SESSION in REQUEST object as : ZODBSESSION
 | 
 | Now I can put ZODB objects in ZODBSESSION using something
 like : 
 | 
 | context.REQUEST.ZODBSESSION.set(object,o)
 | 
 | Thanks to all of you for your precious help.
 
 Your main ZODB will grow everytime you add or remove
 something in
 ZODBSESSION, you're essentially storing the same object
 twice in your
 ZODB.
 
 -- 
 Andrew Milton
 [EMAIL PROTECTED]


Correct. I Quit... :( better not to store ZODB objects in the session and try 
to get some way around.






  
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Need some help to get rid of an InvalidObjectReference exception

2008-08-20 Thread Andrew Milton
+---[ chaouche yacine ]--
|
| Correct. I Quit... :( better not to store ZODB objects in the session and try 
to get some way around.

So now you can go look at the Cache objects that Zope provides :-)

-- 
Andrew Milton
[EMAIL PROTECTED]
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Need some help to get rid of an InvalidObjectReference exception

2008-08-20 Thread chaouche yacine
 +---[ chaouche yacine ]--
 |
 | Correct. I Quit... :( better not to store ZODB objects in
 the session and try to get some way around.
 
 So now you can go look at the Cache objects that Zope
 provides :-)
 
 -- 
 Andrew Milton
 [EMAIL PROTECTED]

If you are talking about RAM cache, HTTP cache etc., I don't know if they'll do 
the trick because, again, it's about caching objects that do not live in the 
ZODB, i.e I cannot go in the ZMI and click the cache tab on a python script or 
a page template because that's not what I am trying to do.

But maybe there's the volatile attributes alternative, and that fails too then 
I have no choice but to do the caching mechanism myself...






  
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Need some help to get rid of an InvalidObjectReference exception

2008-08-20 Thread Andrew Milton
+---[ chaouche yacine ]--
|  +---[ chaouche yacine ]--
|  |
|  | Correct. I Quit... :( better not to store ZODB objects in
|  the session and try to get some way around.
|  
|  So now you can go look at the Cache objects that Zope
|  provides :-)
|  
|  -- 
|  Andrew Milton
|  [EMAIL PROTECTED]
| 
| If you are talking about RAM cache, HTTP cache etc., I don't know if they'll 
do the trick because, again, it's about caching objects that do not live in the 
ZODB, i.e I cannot go in the ZMI and click the cache tab on a python script or 
a page template because that's not what I am trying to do.
| 
| But maybe there's the volatile attributes alternative, and that fails too 
then I have no choice but to do the caching mechanism myself...

Whatever you are doing, you are doing the wrong thing.

You are instantiating persistent objects and not storing them in the
ZODB. This is going to cause your ZODB to grow, so you might as well
store them.

Otherwise you need to make non-persistent versions of the objects you
are trying to 'cache' and use those instead.

-- 
Andrew Milton
[EMAIL PROTECTED]
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Need some help to get rid of an InvalidObjectReference exception

2008-08-20 Thread chaouche yacine


 Whatever you are doing, you are doing the wrong
 thing.
 
 You are instantiating persistent objects and not storing
 them in the
 ZODB. This is going to cause your ZODB to grow, so you
 might as well
 store them.
 
 Otherwise you need to make non-persistent versions of the
 objects you
 are trying to 'cache' and use those instead.
 
 -- 
 Andrew Milton
 [EMAIL PROTECTED]

Not exactly. I am instantiating non persistent objects that do have a reference 
to persistence objects in the form of an attribute, and then trying to cache 
those non persistent objects.

Do the fact that these non persistent objects store a reference to persistent 
ones turn them into persistent ? I am curious to know.

Anyway, I tried the volatile attribute thing 
(http://wiki.zope.org/ZODB/VolatileAttributes) and first tests look fine.

This is how I did the trick :

===
ZODBLivinObject.py
===

from OFS.SimpleItem import SimpleItem
from NonZODBObject import NonZODBObject


class ZODBLivingObject(SimpleItem) :

Hello, I live in the ZODB.

meta_type = ZODBish
def __init__(self):


self.id = ZODBish
self.title = ZODBish

def sayHi(self):


# NonZODBObject stores a reference of self, a ZODB-living object.
nonZODBish = NonZODBObject(self)
# This line breaks everything. Comment it and every thing will be just 
right.
# self.REQUEST.SESSION.set('breakish',nonZODBish)
self.setNonZODBish(nonZODBish)
# This can be seen in the console if runzope
print it's me,nonZODBish.context
return nonZODBish.context

def setNonZODBish(self,p_nonZODBish):


setattr(self,'_v_NonZODBish',p_nonZODBish)

def getNonZODBish(self):


if not hasattr(self,_v_NonZODBish):
self.setNonZODBish(None)
return self._v_NonZODBish


And then I use the setNonZODBish et getNonZODBish methods to set and access the 
cached value.











  
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Need some help to get rid of an InvalidObjectReference exception

2008-08-20 Thread Andrew Milton
+---[ chaouche yacine ]--
| 
|
| Not exactly. I am instantiating non persistent objects that do have a 
reference to persistence objects in the form of an attribute, and then trying 
to cache those non persistent objects.
| 
| Do the fact that these non persistent objects store a reference to persistent 
ones turn them into persistent ? I am curious to know.
| 
| Anyway, I tried the volatile attribute thing 
(http://wiki.zope.org/ZODB/VolatileAttributes) and first tests look fine.

You understand that _v_ attributes are only available in the thread they
were created, and will disappear when the object leaves the object
cache.

If you manage to get a 2nd thread there will be nothing in the _v_
attribute, or wait 10 or so mins between requests...

-- 
Andrew Milton
[EMAIL PROTECTED]
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Need some help to get rid of an InvalidObjectReference exception

2008-08-20 Thread chaouche yacine

 You understand that _v_ attributes are only available in
 the thread they
 were created, and will disappear when the object leaves the
 object
 cache.
 
 If you manage to get a 2nd thread there will be nothing in
 the _v_
 attribute, or wait 10 or so mins between requests...
 
 -- 
 Andrew Milton
 [EMAIL PROTECTED]

Yes this could be dangerous, but in my case these volatile attributes need not 
to be in the cache for a very long time, it's just a matter of 3 or 4 clicks in 
about half a dozen of minutes. But yeah, I'll really have to be careful about 
that, or to recreate them if they're gone (hence the setattr and getattr to 
make sure there's something in self._v_something and create one  if there's not)






  
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Need some help to get rid of an InvalidObjectReference exception

2008-08-19 Thread Dieter Maurer
chaouche yacine wrote at 2008-8-18 09:50 -0700:
Need some help to get rid of an InvalidObjectReference exception
In my zope product, when I try to put some specific object in the session, I 
get this :

2008-08-18T14:51:02 ERROR(200) SiteError 
http://www.afdas.com:8091/noyauafdas/tests/testAdresses
Traceback (most recent call last):
  File /opt/Zope-2.7/lib/python/ZPublisher/Publish.py, line 107, in publish
transactions_manager.commit()
  File /opt/Zope-2.7/lib/python/Zope/App/startup.py, line 222, in commit
get_transaction().commit()
  File /opt/Zope-2.7/lib/python/ZODB/Transaction.py, line 241, in commit
ncommitted += self._commit_objects(objects)
  File /opt/Zope-2.7/lib/python/ZODB/Transaction.py, line 356, in 
 _commit_objects
jar.commit(o, self)
  File /opt/Zope-2.7/lib/python/ZODB/Connection.py, line 452, in commit
dump(state)
InvalidObjectReference: Attempt to store an object from a foreign database 
connection

A given persistent object can only be in one (ZODB-) database, not in several
databases at the same time.

You must copy the persistent object, when you want it to be stored
(also) in another (ZODB-) database.

You can use the _getCopy(destination) method to create such
a copy. _getCopy is defined by OFS.CopySupport.CopySource inherited
by most Zope objects.



-- 
Dieter
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] Need some help to get rid of an InvalidObjectReference exception

2008-08-18 Thread chaouche yacine
Need some help to get rid of an InvalidObjectReference exception


Hi zopers,

In my zope product, when I try to put some specific object in the session, I 
get this :

2008-08-18T14:51:02 ERROR(200) SiteError 
http://www.afdas.com:8091/noyauafdas/tests/testAdresses
Traceback (most recent call last):
  File /opt/Zope-2.7/lib/python/ZPublisher/Publish.py, line 107, in publish
transactions_manager.commit()
  File /opt/Zope-2.7/lib/python/Zope/App/startup.py, line 222, in commit
get_transaction().commit()
  File /opt/Zope-2.7/lib/python/ZODB/Transaction.py, line 241, in commit
ncommitted += self._commit_objects(objects)
  File /opt/Zope-2.7/lib/python/ZODB/Transaction.py, line 356, in 
_commit_objects
jar.commit(o, self)
  File /opt/Zope-2.7/lib/python/ZODB/Connection.py, line 452, in commit
dump(state)
InvalidObjectReference: Attempt to store an object from a foreign database 
connection

after hours of googling and debugging (not very easy because traceback does not 
show the line of your product code that fired the exception), I found the line 
that is breaking everything.

def remonterAdresses(self,p_idEntreprise=0):

Sans arguments, cette methode retourne les adresses stockees en session.

# XXX : attention, p_idEntreprise est totalement ignore si entreprise 
deja en session
entreprise = self.REQUEST.SESSION.get('entreprise')
print GestionnaireEntreprises::remonterAdresses...
if not entreprise :
entreprise = Entreprise(self,p_idEntreprise)
print mise de entreprise en session..
self.REQUEST.SESSION.set('entreprise',entreprise)
print ...mise en session OK

adresses = entreprise.remonterAdresses()
print GestionnaireEntreprises::remonterAdresses OK, adresses = 
,adresses
return adresses

Now, the bug comes form the line 
self.REQUEST.SESSION.set('entreprise',entreprise)

entreprise is an instance of Entreprise. I never put objects of this class in 
the ZODB because I don't need them to persist, they're just temporary. However, 
because Entreprises objects need to access to other objects that are in the 
ZODB, I pass them self as first argument, so that they can use it as a 
context to acquire other objects (for examples, Z SQL Methods). So inside 
Entreprise code, I can do something like self.context.zsql_method_something... 
because self.context is a reference to the caller, which lives in the ZODB. The 
caller is gestionnaireEntrprises.

So my question is : what is wrong with that ? Why do I get this 
InvalidObjectReference ? is it the entreprise object that is in the session ? 
is it the gestionnaireEntreprises that is stored as an attribute of the 
entreprise object ? maybe both ? 

Thank you for any advice.

Zope 2.7
python 2.3
plone 2.0.5




  
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )