That prevents the error but it does not render the references using the list:reference table _format method, they still appear as a list of id's, e.g., [4L, 15L, 9L]
On Thursday, August 13, 2015 at 7:13:56 PM UTC-4, Val K wrote: > > I try 'list:reference table' and it doesn't work at all ! (even > DB-admin!) (2.12.1-stable+timestamp.2015.08.07.07.22.06 (Running on > Rocket 1.2.6, Python 2.7.9)) - run from source on Win7x32 > I got: > <type 'exceptions.TypeError'> isinstance() arg 2 must be a class, type, or > tuple of classes and typesCode listing > > 263. > 264. > 265. > 266. > 267. > 268. > > 269. > 270. > 271. > 272. > > if not value: > return None > from ..adapters import GoogleDatastoreAdapter > refs = None > db, id = self.ref._db, self.ref._id > if isinstance(db._adapter, GoogleDatastoreAdapter): > > def count(values): > return db(id.belongs(values)).select(id) > rx = range(0, len(value), 30) > refs = reduce(lambda a, b: a & b, [count(value[i:i+30]) > > > I think it's a little bug, because there is *conditional import* > GoogleDatastoreAdapter (only if gae) in the __init__.py of adapters > package. Otherwise GoogleDatastoreAdapter = None! > .../adapters/__init__.py: > > ... > > #: load google adapters if needed > if gae is not None: > from .google_adapters import GoogleDatastoreAdapter, GoogleSQLAdapter > # discouraged, for backward compatibility > ADAPTERS['gae'] = GoogleDatastoreAdapter > # add gae adapters > ADAPTERS['google:datastore'] = GoogleDatastoreAdapter > ADAPTERS['google:datastore+ndb'] = GoogleDatastoreAdapter > ADAPTERS['google:sql'] = GoogleSQLAdapter > else: > #: make the import available for BaseAdapter > GoogleDatastoreAdapter = None > > #: make the import available for BaseAdapter - I don't find such import > in base.py > > Probably must be: > if GoogleDatastoreAdapter and isinstance(db._adapter, > GoogleDatastoreAdapter): > I've corrected it and try - it works but row.render whatever doesn't: > > <type 'exceptions.AttributeError'> 'long' object has no attribute 'id' > it's another small bug in *\helpers\methods.py* (class *_repr_ref_list*) > : > > else: > refs = db(id.belongs(value)).select(id) > return refs and ', '.join( > _fieldformat(self.ref, x.id) for x in value) or '' > > > must be just x (not x.id): > > else: > refs = db(id.belongs(value)).select(id) > return refs and ', '.join( > _fieldformat(self.ref, x) for x in value) or '' > > > I've tried it - works > > > > > > On Thursday, August 13, 2015 at 6:44:45 AM UTC+3, Michael Beller wrote: >> >> The error occurs when I use the render() function, e.g., teachers = db( >> db.teacher.id>0).select().render(0) >> >> The render() function works fine without the list:reference fields but >> fails with the list:reference fields. >> >> On Wednesday, August 12, 2015 at 11:23:44 PM UTC-4, Massimo Di Pierro >> wrote: >>> >>> It is only when printed in CSV that it represents with the |. It is all >>> fine: >>> >>> In [1]: db.define_table( >>> >>> ...: 'school', >>> >>> ...: Field('Name'), >>> >>> ...: format='%(Name)s', >>> >>> ...: migrate=True >>> >>> ...: ) >>> >>> Out[1]: <Table school (id,Name)> >>> >>> >>> In [2]: >>> >>> >>> In [2]: db.define_table( >>> >>> ...: 'teacher', >>> >>> ...: Field('Name'), >>> >>> ...: Field('schools', 'list:reference school', label='School >>> Villages'), >>> >>> ...: format='%(Name)s', >>> >>> ...: migrate=True >>> >>> ...: ) >>> >>> Out[2]: <Table teacher (id,Name,schools)> >>> >>> >>> In [3]: >>> >>> >>> In [3]: db.school.insert(Name="a") >>> >>> Out[3]: 1L >>> >>> >>> In [4]: db.school.insert(Name="b") >>> >>> Out[4]: 2L >>> >>> >>> In [5]: db.school.insert(Name="c") >>> >>> Out[5]: 3L >>> >>> >>> In [6]: db.teacher.insert(Name="xxx", schools=[1,2,3]) >>> >>> Out[6]: 1L >>> >>> >>> In [7]: teachers = db(db.teacher.id>0).select() >>> >>> >>> In [8]: print teachers >>> >>> teacher.id,teacher.Name,teacher.schools >>> >>> 1,xxx,|1|2|3| >>> >>> >>> >>> In [9]: print teachers[0].schools >>> >>> [1L, 2L, 3L] >>> >>> On Wednesday, 12 August 2015 07:55:50 UTC-5, Michael Beller wrote: >>>> >>>> db.define_table( >>>> 'school', >>>> Field('Name'), >>>> format='%(Name)s', >>>> migrate=True >>>> ) >>>> >>>> db.define_table( >>>> 'teacher', >>>> Field('Name'), >>>> Field('schools', 'list:reference school', label='School >>>> Villages'), >>>> format='%(Name)s', >>>> migrate=True >>>> ) >>>> >>>> teachers = db(db.teacher.id>0).select().render(0) >>>> >>>> Without the render(), it a Row with the piped school id's, e.g., >>>> 51,sally,|53|52| >>>> >>>> On Wednesday, August 12, 2015 at 1:50:20 AM UTC-4, Massimo Di Pierro >>>> wrote: >>>>> >>>>> Can you show us minimalist code to reproduce the problem? >>>>> >>>>> On Tuesday, 11 August 2015 23:03:24 UTC-5, Michael Beller wrote: >>>>>> >>>>>> I was using web2py 2.10.4 and encountered the error using >>>>>> list:reference: >>>>>> <type 'exceptions.TypeError'> isinstance() arg 2 must be a class, >>>>>> type, or tuple of classes and types >>>>>> >>>>>> I then upgraded to 2.12.2 and applied this fix >>>>>> <https://github.com/web2py/pydal/commit/2172b776b9c41884717902e68900b41c105e0364#diff-114ce07f361177e0669ec9a374ef7d6a> >>>>>> >>>>>> that others referenced in the forums having the same problem. >>>>>> >>>>>> Now I'm getting this error: >>>>>> <type 'exceptions.AttributeError'> 'long' object has no attribute 'id' >>>>>> >>>>>> The error occurs in the render() function when applied to a query. >>>>>> >>>>>> File >>>>>> "/Users/MichaelBeller/Dev/w2p-enriched/gluon/packages/dal/pydal/helpers/methods.py", >>>>>> line 279, in __call__ >>>>>> _fieldformat(self.ref, x.id) for x in value) or '' >>>>>> File >>>>>> "/Users/MichaelBeller/Dev/w2p-enriched/gluon/packages/dal/pydal/helpers/methods.py", >>>>>> line 279, in <genexpr> >>>>>> _fieldformat(self.ref, x.id) for x in value) or '' >>>>>> AttributeError: 'long' object has no attribute 'id' >>>>>> >>>>>> Does anybody else have this problem? >>>>>> >>>>>> Thanks. >>>>>> >>>>>> -- 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.