See the long discussion on zope.sqlalchemy Integration ideas. I think
the simplest way to achieve this is to register a global utility for
each site, with the site name as the utility name perhaps.

You can then register an ISession adapter for the root object in each
site that does:

session = getUtility(ISessionContext, name=sitename)()

Also sqlalchemy.orm.session.object_session can be used to return the
session of a currently mapped object. You could register it as an
adapter for ISession too, and then ISession(context) should return the
session wherever you need it.


2008/6/3 Hermann Himmelbauer <[EMAIL PROTECTED]>:
> Am Dienstag, 3. Juni 2008 12:21 schrieb Laurence Rowe:
>> Laurence Rowe wrote:
>> >> I found it by myself: I registered a zope.sqlalchemy related utility,
>> >> which stores an engine (self.engine = create_engine(DSN,...)) and a
>> >> scoped session (self.Session = scoped_session(sessionmaker...)). These
>> >> two objects cannot be serialized, hence the above problem.
>> >>
>> >> Now I'm unsure what to do about this problem - is there any code
>> >> available that demonstrates how to register SA engines/Sessions as
>> >> utilities?
>> >
>> > The simplest solution is to register the Session object as a global
>> > utility.
>> Though that would be quite unnecessary too ;-). If you are ok with one
>> global scoped session for your app, then just use `from mymodule import
>> Session; session = Session()`.
> Hmmm, it's not that easy: I have multiple sites on one Zope3 instance, whereas
> every site should connect to another database. For that reason, I thought
> about a local utility. However, this results in this serialization error.
> Best Regards,
> Hermann
> --
> GPG key ID: 299893C7 (on keyservers)
> FP: 0124 2584 8809 EF2A DBF9  4902 64B4 D16B 2998 93C7
Zope-Dev maillist  -
**  No cross posts or HTML encoding!  **
(Related lists - )

Reply via email to