alfonsodg / demo-web2py

Apache License 2.0
0 stars 0 forks source link

list:reference represent problem on GAE and 1.91.6 #147

Closed alfonsodg closed 10 years ago

alfonsodg commented 10 years ago

From cfho...@cfhowes.com on January 06, 2011 14:53:16

What steps will reproduce the problem? 1. using web2py 1.91.6 and GAE development server, create the following model: db.define_table('allergen', Field('allergen', length=500, notnull=True, unique=True, requires=IS_NOT_IN_DB(db, 'allergen.allergen')), migrate=migrate)

the link between our data and the blobstore info for an image

db.define_table('blobstore_image', Field('blob_key', 'upload', notnull=True, requires=IS_LENGTH(1048576), represent=lambda image : A('download', _href=URL(r=request, c='gae_blobstore', f='download', args=[image])), label="Image"), Field('image_url', length=500), Field('name', length=128, requires=IS_NOT_IN_DB(db, 'blobstore_image.name')), Field('type', length=128, requires=IS_IN_SET(['store_open_small', 'store_open_large', 'store_closed_small', 'store_closed_large', 'ingredient', 'menu_item_small', 'menu_item_large'])) ) db.define_table('ingredient', Field('name', length=400, notnull=True, unique=True, requires=IS_NOT_IN_DB(db, 'ingredient.name')), Field('allergens', 'list:reference allergen'), Field('images', 'list:reference blobstore_image', requires=IS_IN_DB(db(db.blobstore_image.type=='ingredient'), db.blobstore_image.id,multiple=True)), )

  1. create a record in the ingredient table, leaving allergens and images fields empty
  2. create the following function and call it:

def test(): linkto = URL(r=request, f='update')

rows = db(db.ingredient.id>0).select()
tbl = SQLTABLE(rows,linkto,truncate=128)
return dict(rows=rows,
            tbl=tbl) What is the expected output? What do you see instead? i expected to see a representation of the rows and the SQLTABLE.  instead i got the following error:

File "/home/cfhowes/clients/pump/source/web2py/applications/pumporders/controllers/default.py:test", line 59, in test File "/home/cfhowes/clients/pump/source/web2py/gluon/sqlhtml.py", line 1351, in init r = field.represent(r) File "/home/cfhowes/clients/pump/source/web2py/gluon/dal.py", line 3115, in list_ref_repr refs = r._db(r.id.belongs(ids)).select(r.id) File "/home/cfhowes/clients/pump/source/web2py/gluon/dal.py", line 4509, in select return self.db._adapter.select(self.query,fields,attributes) File "/home/cfhowes/clients/pump/source/web2py/gluon/dal.py", line 2679, in select (items, tablename, fields) = self.select_raw(query,fields,attributes) File "/home/cfhowes/clients/pump/source/web2py/gluon/dal.py", line 2639, in select_raw filters = self.expand(query) File "/home/cfhowes/clients/pump/source/web2py/gluon/dal.py", line 2550, in expand return expression.op(expression.first, expression.second) File "/home/cfhowes/clients/pump/source/web2py/gluon/dal.py", line 2597, in BELONGS return [GAEF(first.name,'in',self.represent(second,first.type),lambda a,b:a in b)] File "/home/cfhowes/clients/pump/source/web2py/gluon/dal.py", line 2327, in represent obj = long(obj) TypeError: long() argument must be a string or a number, not 'list'

at line 3114 of dal.py we have: def list_ref_repr(ids, r=referenced, f=ff): refs = r._db(r.id.belongs(ids)).select(r.id) return (refs and ', '.join(str(f(r,ref.id)) for ref in refs) or '')

and if we add a check for empty ids like below it works: def list_ref_repr(ids, r=referenced, f=ff): if not ids: return None refs = r._db(r.id.belongs(ids)).select(r.id) return (refs and ', '.join(str(f(r,ref.id)) for ref in refs) or '')

note that the images field (with it's own requires, not the default list:reference requires) seems to work just fine without the change.

Original issue: http://code.google.com/p/web2py/issues/detail?id=149

alfonsodg commented 10 years ago

From cfho...@cfhowes.com on January 10, 2011 18:07:10

this has been integrated and most likely can be marked as fixed.

alfonsodg commented 10 years ago

From massimo....@gmail.com on January 10, 2011 18:17:07

Thank for reminding me.

Status: Fixed