I tested further and am not sure now about my proposed fix.
In dal.py, there seem to be two approaches to user-defined primary
keys:
One is to assume that only special tables have an
attribute ._primarykey, and run special case code if hasattr(self,
"_primarykey"), e.g.:
if hasattr(self,'_primarykey'):
rtablename,rfieldname = ref.split('.')
rtable = self._db[rtablename]
rfield = rtable[rfieldname]
# must be PK reference or unique
if rfieldname in rtable._primarykey or
rfield.unique:
The other is to assume all tables have the ._primarykey attribute and
use it without testing for existence, e.g.:
if not orderby and tablenames:
sql_o += ' ORDER BY %s' % ', '.join(['%s.%s'%(t,x) for
t in tablenames for x in (self.db[t]._primarykey or ['id'])])
...which simply won't run if t._primarykey doesn't exist.
Possible fixes:
1. Use defaulted access: self.db[t].get("_primarykey")
2. Always set ._primarykey:
elif primarykey:
self._primarykey = primarykey
new_fields = []
else:
new_fields = [ Field('id', 'id') ]
+ self._primarykey = ["id"]
I haven't spent near enough time in the DAL to know which is best.
Thoughts?