Strange AttributeError on grid edit

22 views
Skip to first unread message

jcrm...@gmail.com

unread,
Apr 30, 2019, 2:43:56 PM4/30/19
to web2py-users
Hello,

I have this grid:
    grid = SQLFORM.grid(
        query
,
        create
=create,
        csv
=False,
        deletable
=deletable,
        details
=False,
        editable
=editable,
       
# Disable delete checkbox in edit form.
        editargs
=dict(deletable=False),
        field_id
=db.equipment.id,
        fields
=fields,
        headers
={'sn_counter.name': T('SN counter')},
        links
=[
           
lambda row: A(
                T
('Pow. supp.'),
                _href
=URL(
                   
'single_equip',
                   
'set_session_vars',
                    args
=[row.equipment.id],
                    vars
={
                       
'table_name': 'equip_ps',
                       
'parent_id_field_name': 'ps_id',
                       
'parent_table_name': 'power_supply',
                       
# Only sid because next page has search
                       
# (which uses vars).
                       
'sid': request.vars.sid,
                   
},
               
),
                _id
='power_supply',
           
),

...

Definitions above the grid are
query = db.equipment.sn_counter_id == db.sn_counter.id

create, deletable and editable are True/False according to the user permissions.
ondelete and onvalidation are a function/None according to the user permissions.

The links on the grid work fine, new record works fine, but edit returns a strange AttributeError.

I was able to identify the problem has been the args argument.
If I change
args=[row.equipment.id],
with
args=[str(row).split("'id': ")[1].split('},')[0]],
everything works, including edit. What I'm doing is extracting the id from the string converted row.

I have no idea why this strange error occurs.

Any ideas?

The complete traceback:
ERROR:web2py:Traceback (most recent call last):
 
File "c:\web2py\gluon\restricted.py", line 219, in restricted
   
exec(ccode, environment)
 
File "c:\web2py\applications\ajc\controllers/equipment.py", line 398, in <modu
le
>
 
File "c:\web2py\gluon\globals.py", line 421, in <lambda>
   
self._caller = lambda f: f()
 
File "c:\web2py\gluon\tools.py", line 3877, in f
   
return action(*a, **b)
 
File "c:\web2py\applications\ajc\controllers/equipment.py", line 341, in index

    user_signature
=False,
 
File "c:\web2py\gluon\sqlhtml.py", line 2610, in grid
    res
= DIV(buttons(view=details, record=record),
 
File "c:\web2py\gluon\sqlhtml.py", line 2532, in buttons
   
elif link(record):
 
File "c:\web2py\applications\ajc\controllers/equipment.py", line 236, in <lamb
da
>
    args
=[row.equipment.id],
 
File "c:\web2py\gluon\packages\dal\pydal\objects.py", line 116, in __getattr__

   
return self.__getitem__(k)
 
File "c:\web2py\gluon\packages\dal\pydal\objects.py", line 100, in __getitem__

    v
= self[key] = lg(key)
 
File "c:\web2py\gluon\packages\dal\pydal\objects.py", line 2490, in __call__
   
raise AttributeError()
AttributeError

My env:
web2py 2.18.5
Python 3.7.1 x86
Firefox 66.0.3 x64
Windows 7 Pro x64 SP1+all upd


Thanks,

JM

Reply all
Reply to author
Forward
0 new messages