Need some help to get rid of an InvalidObjectReference exception

View: New views
19 Messages — Rating Filter:   Alert me  

Need some help to get rid of an InvalidObjectReference exception

by chaouche yacine :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...
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: Need some help to get rid of an InvalidObjectReference exception

by Dieter Maurer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...
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: Need some help to get rid of an InvalidObjectReference exception

by chaouche yacine :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> >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@...
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: Need some help to get rid of an InvalidObjectReference exception

by chaouche yacine :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message




--- On Tue, 8/19/08, Dieter Maurer <dieter@...> wrote:

> From: Dieter Maurer <dieter@...>
> Subject: Re: [Zope] Need some help to get rid of an InvalidObjectReference exception
> To: yacinechaouche@...
> Cc: zope@...
> 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@...
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 )

Parent Message unknown Re: Need some help to get rid of an InvalidObjectReference exception

by chaouche yacine :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

--- On Wed, 8/20/08, chaouche yacine <yacinechaouche@...> wrote:

> From: chaouche yacine <yacinechaouche@...>
> Subject: Re: [Zope] Need some help to get rid of an InvalidObjectReference exception
> To: "Dieter Maurer" <dieter@...>
> Cc: zope@...
> Date: Wednesday, August 20, 2008, 3:22 AM
> --- On Tue, 8/19/08, Dieter Maurer
> <dieter@...> wrote:
>
> > From: Dieter Maurer <dieter@...>
> > Subject: Re: [Zope] Need some help to get rid of an
> InvalidObjectReference exception
> > To: yacinechaouche@...
> > Cc: zope@...
> > 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@...
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: Need some help to get rid of an InvalidObjectReference exception

by Andrew Milton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

+-------[ 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
akm@...
_______________________________________________
Zope maillist  -  Zope@...
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 )

Parent Message unknown Re: Need some help to get rid of an InvalidObjectReference exception

by chaouche yacine :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message




--- On Wed, 8/20/08, chaouche yacine <yacinechaouche@...> 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@...
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: Need some help to get rid of an InvalidObjectReference exception

by chaouche yacine :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

--- On Wed, 8/20/08, chaouche yacine <yacinechaouche@...> wrote:

> From: chaouche yacine <yacinechaouche@...>
> Subject: Re: [Zope] Need some help to get rid of an InvalidObjectReference exception
> To: "Dieter Maurer" <dieter@...>
> Cc: zope@...
> Date: Wednesday, August 20, 2008, 5:12 AM
> --- On Wed, 8/20/08, chaouche yacine
> <yacinechaouche@...> 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@...
> 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@...
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: Need some help to get rid of an InvalidObjectReference exception

by Andrew Milton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

+-------[ 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
akm@...
_______________________________________________
Zope maillist  -  Zope@...
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: Need some help to get rid of an InvalidObjectReference exception

by chaouche yacine :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message




--- On Wed, 8/20/08, Andrew Milton <akm@...> wrote:

> From: Andrew Milton <akm@...>
> Subject: Re: [Zope] Need some help to get rid of an InvalidObjectReference exception
> To: "chaouche yacine" <yacinechaouche@...>
> Cc: zope@...
> 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
> akm@...


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






     
_______________________________________________
Zope maillist  -  Zope@...
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: Need some help to get rid of an InvalidObjectReference exception

by Andrew Milton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

+-------[ 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
akm@...
_______________________________________________
Zope maillist  -  Zope@...
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: Need some help to get rid of an InvalidObjectReference exception

by chaouche yacine :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> +-------[ 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
> akm@...

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@...
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: Need some help to get rid of an InvalidObjectReference exception

by Andrew Milton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

+-------[ 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
| > akm@...
|
| 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
akm@...
_______________________________________________
Zope maillist  -  Zope@...
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: Need some help to get rid of an InvalidObjectReference exception

by chaouche yacine :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



> 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
> akm@...

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@...
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: Need some help to get rid of an InvalidObjectReference exception

by Andrew Milton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

+-------[ 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
akm@...
_______________________________________________
Zope maillist  -