When I use a query which uses a reference type field, I get the error: <type 'exceptions.AttributeError'> 'DAL' object has no attribute 'db' In my code below, db.Units.site_id is a reference field. The error only happens when I use this field and not on other fields of the table.
The relevant traceback seems to be: File "C:/web2py/applications/mgmt/controllers/programs.py" <http://127.0.0.1:8000/admin/default/edit/mgmt/controllers/programs.py>, line 170, in nyserda units = db(db.Units.site_id == 1)._select() File "C:\web2py\gluon\dal.py", line 10359, in _select return adapter._select(self.query,fields,attributes) File "C:\web2py\gluon\dal.py", line 1774, in _select sql_w = ' WHERE ' + self.expand(query) if query else '' File "C:\web2py\gluon\dal.py", line 1541, in expand out = op(first, second, **optional_args) File "C:\web2py\gluon\dal.py", line 1438, in EQ self.expand(second, first.type)) File "C:\web2py\gluon\dal.py", line 1552, in expand return str(self.represent(expression,field_type)) File "C:\web2py\gluon\dal.py", line 3519, in represent return BaseAdapter.represent(self, obj, fieldtype) File "C:\web2py\gluon\dal.py", line 2018, in represent ftype = self.db[p[0]][p[2]].type File "C:\web2py\gluon\dal.py", line 8322, in __getitem__ return self.__getattr__(str(key)) File "C:\web2py\gluon\dal.py", line 8329, in __getattr__ return ogetattr(self, key) AttributeError: 'DAL' object has no attribute 'db' The issues seems to be in line 2018 of dal.py I looked through the code on github but the change happened a while ago, so not sure if it is just something I am doing wrong or the code is buggy. The code snippet is from the represent function (highlighted in yellow). Any suggestions? elif field_is_type('reference'): # reference # check for tablename first referenced = fieldtype[9:].strip() if referenced in self.db.tables: return str(long(obj)) p = referenced.partition('.') if p[2] != '': try: * ftype = self.db[p[0]][p[2]].type* return self.represent(obj, ftype) except (ValueError, KeyError): return repr(obj) elif isinstance(obj, (Row, Reference)): return str(obj['id']) return str(long(obj)) -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.