alfonsodg / demo-web2py

Apache License 2.0
0 stars 0 forks source link

Bug in table insert for keyed table (_primarykey set) #148

Closed alfonsodg closed 10 years ago

alfonsodg commented 10 years ago

From mikepe...@gmail.com on January 07, 2011 02:06:35

What steps will reproduce the problem? 1. Use a legacy keyed table with MSSQL (with primarykey=[...]) Mine: db.define_table('Tbl_Questions', Field('Question_ID', 'integer'), Field('Question_Category', 'string', length=10), ... Field('Mask_Type', 'integer'), primarykey=['Question_ID'], migrate=False, )

  1. Attempt to insert a row (this is my update code for a jqGrid): @service.json def questions_update(): kwargs = request.vars oper = kwargs.pop("oper") id = kwargs.pop("id") if oper == "add": db.Tbl_Questions.insert(kwargs) <---fails elif oper == "edit": db(db.Tbl_Questions.Question_ID == id).update(kwargs) elif oper == "del": db(db.Tbl_Questions.Question_ID == id).delete() What is the expected output? What do you see instead? The row should be inserted. Instead, an exception is thrown: File "C:\myfiles\dev\web2py\gluon\dal.py", line 3875, in insert return self._db._adapter.insert(self,self._listify(fields)) File "C:\myfiles\dev\web2py\gluon\dal.py", line 706, in insert return dict( [ (k,fields[k]) for k in table._primarykey ]) TypeError: list indices must be integers

At this point, the record has been inserted, and the intent is to return a dictionary of primary key name:value entries for the inserted row. But the fields variable is a list of tuples (from _listify), not a dictionary at this point, hence the error.

When this line is commented out, and a simple return value of 1 is returned experimentally, everything goes on to work fine. What version of the product are you using? On what operating system? Windows, latest released version 1.96.1 Please provide any additional information below. I just started using web2py, I am very impressed and pleased with it. Thank you all very much for all your effort. If I have not been clear, or if I'm wrong, feel free to contact me mike@peper.org. Thanks!!!!

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

alfonsodg commented 10 years ago

From mikepe...@gmail.com on March 26, 2011 13:15:49

Coming back to see the status of this item (I cannot allow customers to get official versions, I must give them a hacked version until this bug is fixed in the trunk), I notice I mis-typed the version I found this in, it was 1.91.6, not 1.96.1 (which doesn't exist yet).

alfonsodg commented 10 years ago

From massimo....@gmail.com on June 20, 2011 11:28:15

This is fixed in trunk.

Status: Fixed