A similar error is generated on validators.py at IS_NOT_IN_DB on form
delete processing.

...
  File "/home/alan/web2py-hg/gluon/validators.py", line 553, in
__call__
    elif str(rows[0].id) != str(self.record_id):
  File "/home/alan/web2py-hg/gluon/dal.py", line 4996, in __getattr__
    return self[key]
  File "/home/alan/web2py-hg/gluon/dal.py", line 4987, in __getitem__
    return dict.__getitem__(self, key)
KeyError: 'id'


Here are the changes to validators.py i made to avoid the exception:

(from line 542)
        ...
        table = self.dbset.db[tablename]
        ...
            elif str(rows[0][table.id.name]) != str(self.record_id):
        ...

First the special attribute id.name is retrieved to store the actual
id field name, and then, the Row.id syntax is replaced with dict
element notation

On 21 ene, 19:00, Alan Etkin <[email protected]> wrote:
> I recently updated my web2py source code from the mercurial repository
>
> I think that something has changed in SQLFORM that is incompatible
> with custom id field names declared with:
>
> Field("other_id", ...)
>
> On form processing, record updates stop the app with this error:
>
> Traceback (most recent call last):
>   File "/home/alan/gestionlibre/gestionlibre_gui-hg/controllers/
> appadmin.py", line 178, in update
>     if session.form.accepts(evt.args, formname=None, keepvalues=False,
> dbio=False):
>   File "/home/alan/web2py-hg/gluon/sqlhtml.py", line 1050, in accepts
>     (formname_id, record_id) = (self.record[id_fieldname],
>   File "/home/alan/web2py-hg/gluon/dal.py", line 4987, in __getitem__
>     return dict.__getitem__(self, key)
>
> I managed to solve the problem for updates by changing sqlhtml.py in
> this way:
>
> (Line 1039)
>                 # retrieve the actual id name (for legacy databases)
>                 try:
>                     id_fieldname = self.table.id.name
>                 except (IndexError, AttributeError):
>                     # could not retrieve the table id value
>                     id_fieldname = "id"
>                 # former notation was self.record.id Check for
> compatibility
>                 (formname_id, record_id) = (self.record[id_fieldname],
>                                             request_vars.get('id',
> None))
>
> The problem seems to be related to SQLFORM trying to get the default
> id key from table records, and may reproduce in other instances, since
> I see that the record.id property is being called in other sections of
> the module.
>
> I'd continue with the fix to provide a complete modification of the
> module if the solution provided has no backward compatibility or other
> problems.
>
> Thanks

Reply via email to