Permalink
Browse files

Handle error on GAE when Model objects are used with the form. (closes

…#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...
1 parent 263b710 commit f7faa5c43f054f2ca0f855a8c4cb7133bc2aa700 @anandology anandology committed Jan 31, 2012
Showing with 9 additions and 2 deletions.
  1. +9 −2 web/form.py
View
11 web/form.py
@@ -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):

0 comments on commit f7faa5c

Please sign in to comment.