I'm not sure if these are actual bug fixes or simply misinformed hacks 
(please let me know), but I think they might be useful to the community. My 
notes are for version 1.99.2 so the line numbers may be a little off. Most 
of the changes are the result of trying to get Oracle and multiple key 
tables to work.

I added values for 'reference FK' and 'reference 'TFK' in dal.py for the 
Oracle adapter.
'reference FK': ', CONSTRAINT FK_%(constraint_name)s FOREIGN KEY 
(%(field_name)s) REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s',
'reference TFK': ' CONSTRAINT FK_%(foreign_table)s_PK FOREIGN KEY 
(%(field_name)s) REFERENCES %(foreign_table)s (%(foreign_key)s) ON DELETE 
%(on_delete_action)s',
 
I changed line 1046 in sqlhtml.py per http://tinyurl.com/7wn8sjv which 
seems to allow the crud update page to display.
# Before
record_id = dict((k, request_vars[k]) for k in self.table._primarykey)
# After
record_id = dict((k, request_vars.get(k,None)) for k in 
self.table._primarykey)

I changed line 761 in sqlhtml.py
# Before
self.record_id = dict([(k,record[k]) for k in table._primarykey])
# After
self.record_id = dict([(k,str(record[k])) for k in table._primarykey])
which allows the crud update form to be submitted. The problem lied in the 
update form for dataSource. Since dataSource is keyed by source_id, SQLFORM 
uses source_id as the record_id for any record you edit. Web2py performs a 
security check on the value of the record_id before and after the form was 
submitted. If the record_id changes, web2py complains. Since source_id is 
an integer, web2py saved it as an integer into the record_id. Since 
source_id appears on the update form, it is converted to a string. Since 
num != 'num', a security error occurred. The temporary(?) solution is to 
convert every value in the record_id to a string before form submission.

Changed line 3071 in tools.py
# Before
if not (isinstance(table, self.db.Table) or table in self.db.tables) \
        or not str(record_id).isdigit():
    raise HTTP(404)
# After
if not (isinstance(table, self.db.Table) or table in self.db.tables):
    raise HTTP(404)
This change should allow crud delete to work with keyed databases, since 
line 3090 can accept a dictionary of key assignments. Thus, for the 
dataSource table we can pass in dict(source_id=the_source_id) to 
crud.delete().

Reply via email to