Re: zope.session storage error

Simon Elbaz <[email protected]>
Newsgroups gmane.comp.web.zope.devel
Message-ID <CAPOUM=eaHX9-PSsx3zu_zrZXZab=LugbeYTaCNPpJB70ZL=MeA@mail.gmail.com>
You solved my problem.

After correcting the idiomatic errors and storing the customer ID only, the
error doesn't appear anymore.

Do you have please an explanation ?

Regards
Simon Elbaz

On Tue, Oct 14, 2014 at 1:21 PM, Marius Gedminas <[email protected]> wrote:

> On Tue, Oct 14, 2014 at 12:13:56AM +0200, Simon Elbaz wrote:
> > Hi,
> >
> > Could someone explain me why the following code:
> >
> >     if
> ISession(self.request)['cdc_adama'].__contains__('current_customer'):
> >
>  ISession(self.request)['cdc_adama'].__delitem__('current_customer')
> >     ISession(self.request)['cdc_adama']['current_customer'] = customer
>
> First, a style issue: please don't use __contains__ or __delitem__ this
> way.  Use the idiomatic Python spelling:
>
>     if 'current_customer' in ISession(self.request)['cdc_adama']:
>         del ISession(self.request)['cdc_adama']['current_customer']
>     ISession(self.request)['cdc_adama']['current_customer'] = customer
>
> > triggers the error:
> >
> >   File
> >
> "/home/simon/ADAMA/Src/gui/z3c_dunning/eggs/ZODB-4.0.0a4-py2.7.egg/ZODB/serialize.py",
> > line 352, in persistent_id
> >     "database connection", self._jar, obj,
> > InvalidObjectReference: ('Attempt to store an object from a foreign
> > database connection', <Connection at 7966348c>,
> > <zope.container.btree.BTreeContainer object at 0x7a61282c>)
> >
> > Is the zope.session module opening a new ZODB connection ?
>
> It's not about different ZODB connections.  It's about objects being
> stored in different databases.  And that depends on how your session
> storage is configured in your application.  For example, if you use
> RAMSessionDataContainer then session data lives in a memory-only
> MappingStorage.
>
> Perhaps you can store just the customer ID instead of the entire object?
>
> Regards,
> Marius Gedminas
> --
> http://pov.lt/ -- Zope 3/BlueBream consulting and development
>
> _______________________________________________
> Zope-Dev maillist  -  [email protected]
> https://mail.zope.org/mailman/listinfo/zope-dev
> **  No cross posts or HTML encoding!  **
> (Related lists -
>  https://mail.zope.org/mailman/listinfo/zope-announce
>  https://mail.zope.org/mailman/listinfo/zope )
>
>

_______________________________________________
Zope-Dev maillist  -  [email protected]
https://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists -
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope )
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.