[Z3-sqlos] sqlos and per site databases
Brian Sutherland
jinty at web.de
Fri Dec 9 15:41:05 CET 2005
On Tue, Nov 01, 2005 at 01:51:29PM +0100, Andreas Elvers wrote:
> Hi,
>
> I am having problems with sqlos and local utilities. I have a folder
> which is a site. This site has a local utility which is a psycopg
> adapter named as 'psycopg'. I have registered this name with sqlos. When
> adding a SQLObjectContainer to this site folder my guess is, that this
> container should use the db adapter 'psycopg'.
>
> While adding I get a "'NoneType' object is not callable" in
> connection.py on line 96. This is because queryUtility really does not
> find my local Utility although context point to the newly created
> SQLObjectContainer and the utility name is currect either.
Hi Andreas,
I found you test for the issue in the issue tracker and committed it to
the trunk. Though it is disabled until the issue is fixed.
I can see at least two problems:
* Sometimes the connection descriptor does not have the right context
when querying the utilities. We could probably fix that on a case by
case basis by getting the connection before the sqlobject call with
the right context.
Here is a sci-fi replacement of the container items() method:
def items(self):
"""Return a sequence-like object containing tuples of the form
(name, object) for the objects that appear in the folder.
"""
# we need to get the connection ourselves to avoid breaking
# local
# utilities that set the connection
ut = zapi.getUtility(IConnectionName, context=self)
connection = getConnection(self, ut.name)
# iterate through the factories returning all the results
for factoryName in self.allowedFactories():
factory = zapi.getUtility(IISQLObject, factoryName, context=self)
for obj in factory.select(connection=connection):
name = '%s.%s' % (factoryName, obj.id)
yield (name, contained(obj, parent=self, name=name))
* The connection cache into sqlos.connection only can cope with one
connection name per thread. This will seriously break if you do
something like having two local connections with the same name.
Unfortunately, I don't have the time to fix these now...
--
Brian Sutherland
Metropolis - "it's the first movie with a robot. And she's a woman.
And she's EVIL!!"
More information about the z3-sqlos
mailing list