[storm] infoheritance pattern and lazr.delegates

BožoDragojevič bozo.dragojevic at gmail.com
Mon Jan 19 09:03:07 GMT 2009


Lorenzo Gil Sanchez <lorenzo.gil.sanchez at ...> writes:

> 
> 
> Finally I found some time to try things and I answered myself. 
> Just in case anyone find this useful I'll put a link to the 
> post I wrote explaining how to use lazr.delegates to improve 
> the infoheritance pattern found in the Storm
documentation:http://www.lorenzogil.com/blog/2009/01/18/mapping-inheritance-to-a-rdbms-with-storm-and-lazrdelegates/


According to lazr.delegates docco you'll not be able to do this:

>>> secret_agent = store.find(SecretAgent,
                              SecretAgent.name==u'James Bond').one()

because the SecretAgent.name will evaluate to the lazr.delegates Passthrough
descriptor, which Storm will not grok.

At joost we have Storm-mapped db schema that also uses use the infoheritance
pattern, which one learns to hate. :-P

We're using Storm's Proxy object and a custom metaclass, not unlike yours, but
one that installs proxied properties 'manually' without introspection. It would
be probably not too difficult to make lazr.delegates use Proxy class instead of
it's Passthrough tho. The bove then correctly translates to a select with a join
on the Person table.


Once you start optimizing the number of silly queries the code starts looking
like this:

>>> secret_agent, _p = store.find((SecretAgent, Person),
                                  SecretAgent.name == u'James Bond').one()
>>> print secret_agent.name

or the print will have to execute another query to lazy-fetch the base-class and
the latency goes through the roof. and the nice abstraction you've bult starts
leaking to all users....

And it's still not bullet-proof, tho. This doesn't work:

>>> Spy = ClassAlias(SecretAgent)
>>> store.find(SecretAgent, SecretAgent.name == Spy.name, SecretAgent.id !=
Spy.id).count()

Which could be argued is a feature missing from ClassAlias, as one can validly
use Proxies outside the infoheritance pattern, but then, explicit being better
than implicit... who knows.

Bozzo




More information about the storm mailing list