[Zope-dev] bug in zpatterns-0.4 ?
mike
mike@if-site.com
Tue, 27 Jun 2000 15:13:58 +0800
Jephte CLAIN wrote:
>
> mike wrote:
> > Jephte CLAIN wrote:
> > > Rack.createItem (low level method) first calls Rack.getItem (higher
> > > level method) to check the existence of the item.
> > > This causes infinite loop in certain cases. It should (IMHO) call
> > > Rack.retrieveItem instead
> > Could you provide an example please?
> My data is located in an SQL database. I want to have some associated
> data in ZODB. ZPatterns is a perfect fit for this. When I first access a
> SQL record, the corresponding data is created in ZODB:
>
> def getItem(self, key):
> if self.sql_get(key=key):
> # ok it exists in the SQL database
> item = Rack.getItem(self, key)
> if item is None:
> # it does not exist in ZODB, create it
> item = Rack.newItem(self, key)
> else:
> item = None
> return item
>
> This causes infinite loop because Rack.newItem calls Rack.createItem
> which calls my (modified) getItem
1. Leave getItem untouched. Move all that SQL-related stuff into the
retrieveItem method which *is intended* to be overriden.
2. Move newItem stuff into Specialist. You have mixed 'Restaurant' and
the 'FoodStore' in this snippet :-) Do this instead:
Specialist:
def getItem( self, key) :
item = self._src().getItem( key)
if item is None :
item = self._src().newItem( key)
return item
def _src( self) :
return self.rackList[0].__of__( self)
Rack:
def retrieveItem( self, key) :
item = self.sql_get( key)
blah blah blah ...
return item
Mike