The record was there.

That's the problem.  The shortcut was erroneously reporting that it was 
gone.

On Tuesday, November 6, 2012 2:40:38 PM UTC-5, Niphlod wrote:
>
> del db.sometable[something] requires that the id == something exists.
> db(db.sometable.id == something).delete() instead returns the number of 
> records deleted if there was any, otherwise it simply deletes nothing.
>
> On Tuesday, November 6, 2012 8:14:33 PM UTC+1, Cliff Kachinske wrote:
>>
>> This code works.  Note the commented out line.
>>
>>     for v in form.vars:
>>         if v[:7] == 'remove_' and form.vars[v] == 'on':
>>             # del db.class_users[v[7:]]
>>             db(db.class_users.id==v[7:]).delete()
>>
>>
>> This code, which should be equivalent, raises the exception shown below.
>>
>>     for v in form.vars:
>>         if v[:7] == 'remove_' and form.vars[v] == 'on':
>>             del db.class_users[v[7:]]
>>
>>
>> Traceback (most recent call last):
>>   File "/home/cjk/w2p09/web2py/gluon/restricted.py", line 209, in restricted
>>     exec ccode in environment
>>   File 
>> "/home/cjk/w2p09/web2py/applications/Training/controllers/class_users.py" 
>> <http://localhost:8000/admin/default/edit/Training/controllers/class_users.py>,
>>  line 371, in <module>
>>   File "/home/cjk/w2p09/web2py/gluon/globals.py", line 186, in <lambda>
>>     self._caller = lambda f: f()
>>   File "/home/cjk/w2p09/web2py/gluon/tools.py", line 2809, in f
>>     return action(*a, **b)
>>   File 
>> "/home/cjk/w2p09/web2py/applications/Training/controllers/class_users.py" 
>> <http://localhost:8000/admin/default/edit/Training/controllers/class_users.py>,
>>  line 165, in list_
>>     if form.process(onvalidation=do_updates).accepted:
>>   File "/home/cjk/w2p09/web2py/gluon/html.py", line 2108, in process
>>     self.validate(**kwargs)
>>   File "/home/cjk/w2p09/web2py/gluon/html.py", line 2055, in validate
>>     if self.accepts(**kwargs):
>>   File "/home/cjk/w2p09/web2py/gluon/html.py", line 1969, in accepts
>>     onvalidation(self)
>>   File 
>> "/home/cjk/w2p09/web2py/applications/Training/controllers/class_users.py" 
>> <http://localhost:8000/admin/default/edit/Training/controllers/class_users.py>,
>>  line 134, in do_updates
>>     del db.class_users[v[7:]]
>>   File "/home/cjk/w2p09/web2py/gluon/dal.py", line 7691, in __delitem__
>>     raise SyntaxError, 'No such record: %s' % key
>> SyntaxError: No such record: 7
>>
>>

-- 



Reply via email to