Strange error on grid edit

28 views
Skip to first unread message

João Matos

unread,
Mar 28, 2019, 8:41:23 AM3/28/19
to web...@googlegroups.com
Hello,

I have this grid

        # Hidden fields in grid and edit/view form.
        db
.opt.canceled_on.readable = False
        db
.opt.canceled_by.readable = False
        db
.opt.cancel_approved_by.readable = False

        query
= ((db.opt.is_active == True) & (db.opt.opt_cat_id == db.opt_cat.id))

        grid
= SQLFORM.grid(
            query
,
            csv
=False,
            deletable
=False,
            details
=False,
            fields
=[
                db
.opt.id,
                db
.opt.name,
                db
.opt_cat.name,
                db
.opt_cat.name_en,
           
],
            headers
={'opt_cat.name': T('Category'), 'opt_cat.name_en': T('Category')},
            links
=[
               
lambda row: A(
                    SPAN
(T('Delete'), _class='buttontext button', _title='Delete'),
                    _href
=URL('get_approval', args=[row.opt.id], user_signature=True),
                    _class
='button btn btn-default btn-secondary',
               
),
           
],
            maxtextlength
=GRID_COL_LEN_FOR_TEXT,
            ondelete
=on_delete,  # Grid only.
            onvalidation
=on_validation,  # Form only.
           
orderby=db.opt.name,
            paginate
=session.auth.user.pagination,
           
# represent_none='',  # Grid and view form only.
       
)

If I select the Delete button (link) everything works as expected.

If I select the auto-created Edit button, web2py returns this strange error

ERROR:web2py:Traceback (most recent call last):
 
File "C:\web2py\gluon\packages\dal\pydal\objects.py", line 107, in __getattr__

   
return self.__getitem__(k)
 
File "C:\web2py\gluon\packages\dal\pydal\objects.py", line 94, in __getitem__
   
raise KeyError(key)
KeyError: 'opt'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
 
File "C:\web2py\gluon\restricted.py", line 219, in restricted
   
exec(ccode, environment)
 
File "c:\web2py\applications\ajc\controllers/opt.py", line 537, in <module>
 
File "C:\web2py\gluon\globals.py", line 421, in <lambda>
   
self._caller = lambda f: f()
 
File "C:\web2py\gluon\tools.py", line 3868, in f
   
return action(*a, **b)
 
File "c:\web2py\applications\ajc\controllers/opt.py", line 245, in index
    paginate
=session.auth.user.pagination,
 
File "C:\web2py\gluon\sqlhtml.py", line 2583, in grid
    res
= DIV(buttons(view=details, record=record),
 
File "C:\web2py\gluon\sqlhtml.py", line 2505, in buttons
   
elif link(record):
 
File "c:\web2py\applications\ajc\controllers/opt.py", line 237, in <lambda>
    _href
=URL('get_approval', args=[row.opt.id], user_signature=True),
 
File "C:\web2py\gluon\packages\dal\pydal\objects.py", line 109, in __getattr__

   
raise AttributeError
AttributeError


If I comment the links parameter, the edit works.

Thanks,

JM



João Matos

unread,
Mar 28, 2019, 8:56:46 AM3/28/19
to web2py-users
I was able to "solve" it with a kludge.
I changed this

_href=URL('get_approval', args=[row.opt.id], user_signature=True),

to this

_href=URL('get_approval', args=[str(row).split("'id': ")[1].split(',')[0]], user_signature=True),

and now everything works.

But I still don't understand why the strange error.

Any ideas?

Thanks,

JM
Reply all
Reply to author
Forward
0 new messages