[z3] [Fwd: Re: [Zope3-Users] sqlos - getting factory of NoneType]

Christian Lück christian.lueck at ruhr-uni-bochum.de
Mon Jan 9 20:52:38 CET 2006


Hi Brian!

Brian Sutherland wrote:
> On Sat, Jan 07, 2006 at 06:26:19PM +0000, Christian Lück wrote:
>> Hi
>> 
>> The problem with sqlos seems: It does only work if ONE AND ONLY ONE
>> factory for the content component (interface) in question is registered.
>> And this one-and-only factory has to be registered with the
>> zcml-directive in a special sqlos namespace, ie.
>> 
>>   <sqlos:factory
>>       id="quotationtool.BookSQLObject"
>>       component=".book.Book"
>>       title="BookSQLObject"
>>       description="A book object for the sql resourcedb."
>>       />
>> 
>> When a second factory is registered for the same interface, ie.
>> 
>>   <factory
>>       id="quotationtool.BookWithInitialValues"
>>       component=".book.BookFactory"
>>       title="BookWithInitialValues"
>>       description="A factory for book object with initial values."
>>       />
>> 
>> sqlos fails to get the objects stored on the database (you get blank
>> browser pages).
>> The reason seems to be the implementation of
>> sqlos.container.SQLObjectContainer, which maps between sql-unique-keys
>> (SQLObject-names) and zope-object-names. The mapping mechanism makes use
>> of the factory.
> 
> Yes, I have seen this problem before. You cannot mix sqlos:factory and
> factory and expect things to work.
> 
> And yes, this is a _big_ problem which I think requires a re-think of
> how we do this. But that re-think is not yet thunk.
> 
> So please try this patch (untested). If it works for you, I will add it
> to the source.
> 
> Index: container.py
> ===================================================================
> --- container.py        (revision 21506)
> +++ container.py        (working copy)
> @@ -106,7 +106,9 @@
>          (name, object) for the objects that appear in the folder.
>          """
>          for factoryName in self.allowedFactories():
> -            factory = zapi.getUtility(IISQLObject, factoryName, context=self)
> +            factory = zapi.queryUtility(IISQLObject, factoryName, context=self)
> +            if factory is None:
> +                continue
>              for obj in factory.select():
>                  name = '%s.%s' % (factoryName, obj.id)
>                  yield (name, contained(obj, parent=self, name=name))
> 

No, this does not work for me. The problem with the "None type" was not
mine. I was answering to an other email. - I was facing the analgue
problem of several factories returned by the allowedFactories() method
which caused errors.

Well I have found a solution now. See the diff I have attached.

1) First of all we define a marker Interface ISQLObjectFactory, see what
I added to interfaces.__init__.py.

2) Then we implement this marker interface by factories registered by
the <sqlos:factory> directive. See what I added to metaconfigure.py.

3) Then we check for this marker interface in the allowedFactories()
method of SQLObjectContainer. Have a look at what I added to container.py
Well, in your diff you added the check for "None type" to the items()
method. I think one should rather check the factories in the
allowedFactories() method already. For a) allowedFactories() could be
and in fact is called somewhere else and allways only our sqlos:factory
is an allowed factory for things relavat in SQLObjectContainer; b) the
allowedFactory() method is sqlos specific, it's not a common thing
specified in any zope interface.

This way we achieve this:

- sqlos gets more tyres on the standard zope3 highway: We can now
register <zope:factory> etc. besides <sqlos:factory> without getting errors.

- Since all changes are sqlos internal sqlos applications keep running
without any changes -- provided zcml (the <sqlos:factory> - directive)
was used to wire things together.



>> This way it works, I see the sql-objects and can even edit them :) - But
>> works yust to run into the next bigger problem... (I can't create
>> objects due to rollback problems) :((((
> 
> If you post a traceback here, there is a chance someone can give you a
> quick answer.
> 

Well, this was due to the incompatibility regarding the z3 standard two
step process of adding content. You already read about my solution...


Kind Regards,
Christian

PS. It was the first time I created a diff. I'm not sure if one can use
it at all, because of the filenames.
Do you know a good HOWTO, maybe zope specific?

PS2. Maybe we should check for "None type", too.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sqlos.diff
Type: text/x-patch
Size: 2235 bytes
Desc: not available
Url : http://codespeak.net/pipermail/z3/attachments/20060109/317f1025/sqlos.bin


More information about the z3 mailing list