Skip to content

Commit

Permalink
Handle error on GAE when Model objects are used with the form. (closes
Browse files Browse the repository at this point in the history
…webpy#134)

The `has_key` method of Model object doesn't take any arugments and the
form module expects that it takes one argument. Handled it by catching
and ignoring the TypeError.
  • Loading branch information
anandology committed Jan 31, 2012
1 parent 263b710 commit f7faa5c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions web/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@
import utils, net

def attrget(obj, attr, value=None):
if hasattr(obj, 'has_key') and obj.has_key(attr): return obj[attr]
if hasattr(obj, attr): return getattr(obj, attr)
try:
if hasattr(obj, 'has_key') and obj.has_key(attr):
return obj[attr]
except TypeError:
# Handle the case where has_key takes different number of arguments.
# This is the case with Model objects on appengine. See #134
pass
if hasattr(obj, attr):
return getattr(obj, attr)
return value

class Form(object):
Expand Down

0 comments on commit f7faa5c

Please sign in to comment.