I'm running into a weird "lazy tables" bug. I have about 32 tables defined
and I'm running into a error when I try to open a controller on a table
that references another. The referenced table doesn't show up in the DAL
and web2py throws an error.
I can see the table during "define_table" and I see it added to the
_LAZY_TABLES list. But later, when the table is referenced, it does NOT
show up in the list when I am performing _getattr_ on the name of the table
in the DAL instance. It's like it magically disappears between the
"define_table" and the time the controller is executed.
It seems like the problem is here, in the dal.py file:
def define_table(
self,
tablename,
*fields,
**args
):
if not isinstance(tablename,str):
raise SyntaxError, "missing table name"
elif hasattr(self,tablename) or tablename in self.tables:
if not args.get('redefine',False):
raise SyntaxError, 'table already defined: %s' % tablename
...etc
The call to "hasattr" is processed as a call to the routine "__getattr__"
shown below:
def __getattr__(self, key):
if ogetattr(self,'_lazy_tables') and \
key in ogetattr(self,'_LAZY_TABLES'):
tablename, fields, args = self._LAZY_TABLES.pop(key)
return self.lazy_define_table(tablename,*fields,**args)
return ogetattr(self, key)
But __getattr__ throws an exception if the key is not present, yet the
define_table code which calls it does not look for or process the
exception. Something is amiss in this code but I'm not in tune enough to
figure out the original intent of "hasattr" in this context.
Am I missing something? (probably)
-- Joe B.
--