Error deleting db rows when referenced files are missing

33 views
Skip to first unread message

Boa

unread,
Feb 21, 2016, 8:46:26 PM2/21/16
to web...@googlegroups.com

I have a program with a table that pertains to user avatar images. The 'f_user_id' field in the table references user ids, and the table contains upload fields referring to image files and their corresponding thumbnails.

Running the following function produces an error:

def delete_record_by_user_id(self, user_id):
     
self.db(self.db.auth_avatar.f_user_id == user_id).delete()

The error is:

...
File "...\web2py\gluon\packages\dal\pydal\objects.py", line 2045, in delete
 
if any(f(self) for f in table._before_delete): return 0
File "...\web2py\gluon\packages\dal\pydal\objects.py", line 2045, in <genexpr>
 
if any(f(self) for f in table._before_delete): return 0
File "...\web2py\gluon\packages\dal\pydal\objects.py", line 2137, in delete_uploaded_files
 items
[2][:2])

IndexError: list index out of range

The error is generated in the delete_uploaded_files() function in pydal's objects.py.

Some of the entries in the table were missing file references. Deleting the entries with the missing files made it possible to use my
'
delete_record_by_user_id' function with no errors being generated.

A bug that caused a comparable issue was found some time ago.

Boa

unread,
Feb 22, 2016, 11:55:32 AM2/22/16
to web2py-users
To elaborate - this bug pops up when all of the following conditions are met:

  • user is deleting a row from a table with an 'upload' field
  • the 'upload' field's 'uploadseparate' parameter is set to 'True'
  • the filename stored in the 'upload' field is missing or incorrectly formatted (i.e. the number of components in the filename, separated by '.', is below a certain minimum number)

When deleting a row with an upload field, pydal's delete_uploaded_files() function attempts to get the name of the file, and to split that filename into a list of components, using a period as the delimiter. If there is no filename present, or if the filename doesn't have a certain minimum number of components, this generates an error.

Unless I misinterpreted something, this situation presents a serious problem for anyone using tables with 'upload' fields with uploadseparate = True.
Reply all
Reply to author
Forward
0 new messages