Discussion:
[FE-discuss] KeyError on validation failure after upgrading formencode
John Dickson
2009-03-10 11:32:15 UTC
Permalink
Hi folks

I've recently run into lots of problems with validation in an app of mine,
after upgrading to formencode 1.2.x. This is a Pylons-based app (I've also
just upgraded Pylons from 0.9.6 to 0.9.7), which has been working fine for a
number of people until these upgrades. I've been beating my head against a
brick wall trying to diagnose this for a couple of days now, and still
haven't got anywhere, so I'd be *really* grateful for any pointers you could
give.

I have to say, though, that I'm pretty much a newbie on formencode. I'm
also also only guessing that this is a formencode issue, but it may well be
Pylons.

My controllers use the Pylons @validate decorator. Everything is fine if
there are no errors detected by the decorator (using a subclass of Schema),
but if any validation failure occurs I get a KeyError when trying to run the
controller method to redisplay the form. Examining the request, I see that
params, GET and POST are all empty (UnicodeMultiDict objects), while the
WSGI webob._parsed_post_vars variable seems to have all my POST fields in it
(exactly what I'd have expected to see in params).

I'm including a stack trace below, in case that's of any assistance. Thanks
in advance for your help.

Cheers .................................... John Dickson

Traceback (most recent call last):
File "/home/johnd/python/jcr-0.6.7/jcr/lib/base.py", line 98, in __call__
return WSGIController.__call__(self, environ, start_response)
File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py",
line 221, in __call__
response = self._dispatch_call()
File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py",
line 172, in _dispatch_call
response = self._inspect_call(func)
File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py",
line 107, in _inspect_call
result = self._perform_call(func, args)
File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py",
line 60, in _perform_call
return func(**args)
File "<string>", line 2, in upload
File
"/usr/lib/python2.5/site-packages/AuthKit-0.4.3-py2.5.egg/authkit/authorize/pylons_adaptors.py",
line 36, in validate
return permission.check(app, request.environ, self.start_response)
File
"/usr/lib/python2.5/site-packages/AuthKit-0.4.3-py2.5.egg/authkit/permissions.py",
line 177, in check
return app(environ, start_response)
File
"/usr/lib/python2.5/site-packages/AuthKit-0.4.3-py2.5.egg/authkit/authorize/pylons_adaptors.py",
line 35, in app
return func(self, *args, **kwargs)
File "<string>", line 2, in upload
File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/decorators/__init__.py",
line 161, in wrapper
response = self._dispatch_call()
File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py",
line 172, in _dispatch_call
response = self._inspect_call(func)
File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py",
line 107, in _inspect_call
result = self._perform_call(func, args)
File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py",
line 60, in _perform_call
return func(**args)
File "<string>", line 2, in index
File
"/usr/lib/python2.5/site-packages/AuthKit-0.4.3-py2.5.egg/authkit/authorize/pylons_adaptors.py",
line 36, in validate
return permission.check(app, request.environ, self.start_response)
File
"/usr/lib/python2.5/site-packages/AuthKit-0.4.3-py2.5.egg/authkit/permissions.py",
line 177, in check
return app(environ, start_response)
File
"/usr/lib/python2.5/site-packages/AuthKit-0.4.3-py2.5.egg/authkit/authorize/pylons_adaptors.py",
line 35, in app
return func(self, *args, **kwargs)
File
"/home/johnd/python/jcr-0.6.7/jcr/controllers/projectadmin/selectfileset.py",
line 52, in index
c.projectId = int(request.params['projectId'])
File "build/bdist.linux-i686/egg/webob/multidict.py", line 314, in
__getitem__
return self._decode_value(self.multi.__getitem__(self._encode_key(key)))
File "build/bdist.linux-i686/egg/webob/multidict.py", line 440, in
__getitem__
raise KeyError(key)
KeyError: 'projectId'
Ian Bicking
2009-03-12 18:42:46 UTC
Permalink
I'm wonder if perhaps this is an AuthKit/WebOb conflict. It might be
that AuthKit is reading in the parameters of POST requests in such a
way that WebOb can't see them. You could test by creating a POST form
with a simple controller, and seeing if the POST variables get
swallowed. It isn't necessarily AuthKit that is swallowing them, but
it seems like a good chance (disabling AuthKit and testing would make
it clear).
Post by John Dickson
Hi folks
I've recently run into lots of problems with validation in an app of mine,
after upgrading to formencode 1.2.x.  This is a Pylons-based app (I've also
just upgraded Pylons from 0.9.6 to 0.9.7), which has been working fine for a
number of people until these upgrades.  I've been beating my head against a
brick wall trying to diagnose this for a couple of days now, and still
haven't got anywhere, so I'd be *really* grateful for any pointers you could
give.
I have to say, though, that I'm pretty much a newbie on formencode.  I'm
also also only guessing that this is a formencode issue, but it may well be
Pylons.
there are no errors detected by the decorator (using a subclass of Schema),
but if any validation failure occurs I get a KeyError when trying to run the
controller method to redisplay the form.  Examining the request, I see that
params, GET and POST are all empty (UnicodeMultiDict objects), while the
WSGI webob._parsed_post_vars variable seems to have all my POST fields in it
(exactly what I'd have expected to see in params).
I'm including a stack trace below, in case that's of any assistance.  Thanks
in advance for your help.
Cheers .................................... John Dickson
  File "/home/johnd/python/jcr-0.6.7/jcr/lib/base.py", line 98, in __call__
    return WSGIController.__call__(self, environ, start_response)
  File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py",
line 221, in __call__
    response = self._dispatch_call()
  File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py",
line 172, in _dispatch_call
    response = self._inspect_call(func)
  File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py",
line 107, in _inspect_call
    result = self._perform_call(func, args)
  File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py",
line 60, in _perform_call
    return func(**args)
  File "<string>", line 2, in upload
  File
"/usr/lib/python2.5/site-packages/AuthKit-0.4.3-py2.5.egg/authkit/authorize/pylons_adaptors.py",
line 36, in validate
    return permission.check(app, request.environ, self.start_response)
  File
"/usr/lib/python2.5/site-packages/AuthKit-0.4.3-py2.5.egg/authkit/permissions.py",
line 177, in check
    return app(environ, start_response)
  File
"/usr/lib/python2.5/site-packages/AuthKit-0.4.3-py2.5.egg/authkit/authorize/pylons_adaptors.py",
line 35, in app
    return func(self, *args, **kwargs)
  File "<string>", line 2, in upload
  File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/decorators/__init__.py",
line 161, in wrapper
    response = self._dispatch_call()
  File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py",
line 172, in _dispatch_call
    response = self._inspect_call(func)
  File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py",
line 107, in _inspect_call
    result = self._perform_call(func, args)
  File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py",
line 60, in _perform_call
    return func(**args)
  File "<string>", line 2, in index
  File
"/usr/lib/python2.5/site-packages/AuthKit-0.4.3-py2.5.egg/authkit/authorize/pylons_adaptors.py",
line 36, in validate
    return permission.check(app, request.environ, self.start_response)
  File
"/usr/lib/python2.5/site-packages/AuthKit-0.4.3-py2.5.egg/authkit/permissions.py",
line 177, in check
    return app(environ, start_response)
  File
"/usr/lib/python2.5/site-packages/AuthKit-0.4.3-py2.5.egg/authkit/authorize/pylons_adaptors.py",
line 35, in app
    return func(self, *args, **kwargs)
  File
"/home/johnd/python/jcr-0.6.7/jcr/controllers/projectadmin/selectfileset.py",
line 52, in index
    c.projectId = int(request.params['projectId'])
  File "build/bdist.linux-i686/egg/webob/multidict.py", line 314, in
__getitem__
    return self._decode_value(self.multi.__getitem__(self._encode_key(key)))
  File "build/bdist.linux-i686/egg/webob/multidict.py", line 440, in
__getitem__
    raise KeyError(key)
KeyError: 'projectId'
------------------------------------------------------------------------------
_______________________________________________
FormEncode-discuss mailing list
https://lists.sourceforge.net/lists/listinfo/formencode-discuss
--
Ian Bicking | http://blog.ianbicking.org
John Dickson
2009-03-12 22:57:27 UTC
Permalink
Hi Ian

Thanks for the AuthKit suggestion.

I repeated the test (submitting the form with all fields empty, which fails
validation) with the AuthKit decorator commented out on both the form
display and submission methods, and got the same end result (KeyError on
trying to use a parameter from request.params in the form display method,
after validation failure). The stack trace looks the same (but of course
shorter), and at a quick glance the WSGI variables (on the Pylons error
debug page) look about the same, particularly the webob._parsed_post_vars
variable.

Any suggestions about what I should try next? Would more/different
information about my environment or code help? Also, am I asking the
question on the correct list?

Anyway, thanks again for your assistance.
John
Post by Ian Bicking
I'm wonder if perhaps this is an AuthKit/WebOb conflict. It might be
that AuthKit is reading in the parameters of POST requests in such a
way that WebOb can't see them. You could test by creating a POST form
with a simple controller, and seeing if the POST variables get
swallowed. It isn't necessarily AuthKit that is swallowing them, but
it seems like a good chance (disabling AuthKit and testing would make
it clear).
Post by John Dickson
Hi folks
I've recently run into lots of problems with validation in an app of
mine,
Post by John Dickson
after upgrading to formencode 1.2.x. This is a Pylons-based app (I've
also
Post by John Dickson
just upgraded Pylons from 0.9.6 to 0.9.7), which has been working fine
for a
Post by John Dickson
number of people until these upgrades. I've been beating my head against
a
Post by John Dickson
brick wall trying to diagnose this for a couple of days now, and still
haven't got anywhere, so I'd be *really* grateful for any pointers you
could
Post by John Dickson
give.
I have to say, though, that I'm pretty much a newbie on formencode. I'm
also also only guessing that this is a formencode issue, but it may well
be
Post by John Dickson
Pylons.
there are no errors detected by the decorator (using a subclass of
Schema),
Post by John Dickson
but if any validation failure occurs I get a KeyError when trying to run
the
Post by John Dickson
controller method to redisplay the form. Examining the request, I see
that
Post by John Dickson
params, GET and POST are all empty (UnicodeMultiDict objects), while the
WSGI webob._parsed_post_vars variable seems to have all my POST fields in
it
Post by John Dickson
(exactly what I'd have expected to see in params).
I'm including a stack trace below, in case that's of any assistance.
Thanks
Post by John Dickson
in advance for your help.
Cheers .................................... John Dickson
File "/home/johnd/python/jcr-0.6.7/jcr/lib/base.py", line 98, in
__call__
Post by John Dickson
return WSGIController.__call__(self, environ, start_response)
File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py",
Post by John Dickson
line 221, in __call__
response = self._dispatch_call()
File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py",
Post by John Dickson
line 172, in _dispatch_call
response = self._inspect_call(func)
File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py",
Post by John Dickson
line 107, in _inspect_call
result = self._perform_call(func, args)
File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py",
Post by John Dickson
line 60, in _perform_call
return func(**args)
File "<string>", line 2, in upload
File
"/usr/lib/python2.5/site-packages/AuthKit-0.4.3-py2.5.egg/authkit/authorize/pylons_adaptors.py",
Post by John Dickson
line 36, in validate
return permission.check(app, request.environ, self.start_response)
File
"/usr/lib/python2.5/site-packages/AuthKit-0.4.3-py2.5.egg/authkit/permissions.py",
Post by John Dickson
line 177, in check
return app(environ, start_response)
File
"/usr/lib/python2.5/site-packages/AuthKit-0.4.3-py2.5.egg/authkit/authorize/pylons_adaptors.py",
Post by John Dickson
line 35, in app
return func(self, *args, **kwargs)
File "<string>", line 2, in upload
File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/decorators/__init__.py",
Post by John Dickson
line 161, in wrapper
response = self._dispatch_call()
File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py",
Post by John Dickson
line 172, in _dispatch_call
response = self._inspect_call(func)
File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py",
Post by John Dickson
line 107, in _inspect_call
result = self._perform_call(func, args)
File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py",
Post by John Dickson
line 60, in _perform_call
return func(**args)
File "<string>", line 2, in index
File
"/usr/lib/python2.5/site-packages/AuthKit-0.4.3-py2.5.egg/authkit/authorize/pylons_adaptors.py",
Post by John Dickson
line 36, in validate
return permission.check(app, request.environ, self.start_response)
File
"/usr/lib/python2.5/site-packages/AuthKit-0.4.3-py2.5.egg/authkit/permissions.py",
Post by John Dickson
line 177, in check
return app(environ, start_response)
File
"/usr/lib/python2.5/site-packages/AuthKit-0.4.3-py2.5.egg/authkit/authorize/pylons_adaptors.py",
Post by John Dickson
line 35, in app
return func(self, *args, **kwargs)
File
"/home/johnd/python/jcr-0.6.7/jcr/controllers/projectadmin/selectfileset.py",
Post by John Dickson
line 52, in index
c.projectId = int(request.params['projectId'])
File "build/bdist.linux-i686/egg/webob/multidict.py", line 314, in
__getitem__
return
self._decode_value(self.multi.__getitem__(self._encode_key(key)))
Post by John Dickson
File "build/bdist.linux-i686/egg/webob/multidict.py", line 440, in
__getitem__
raise KeyError(key)
KeyError: 'projectId'
------------------------------------------------------------------------------
Post by John Dickson
_______________________________________________
FormEncode-discuss mailing list
https://lists.sourceforge.net/lists/listinfo/formencode-discuss
--
Ian Bicking | http://blog.ianbicking.org
--
/Angle-parked in a parallel universe.../
Ian Bicking
2009-03-12 23:18:58 UTC
Permalink
Probably it would be better to ask on the Pylons list, there's a good
chance someone else has seen this problem and will recognize it.
Post by John Dickson
Hi Ian
Thanks for the AuthKit suggestion.
I repeated the test (submitting the form with all fields empty, which fails
validation) with the AuthKit decorator commented out on both the form
display and submission methods, and got the same end result (KeyError on
trying to use a parameter from request.params in the form display method,
after validation failure).  The stack trace looks the same (but of course
shorter), and at a quick glance the WSGI variables (on the Pylons error
debug page) look about the same, particularly the webob._parsed_post_vars
variable.
Any suggestions about what I should try next?  Would more/different
information about my environment or code help?  Also, am I asking the
question on the correct list?
Anyway, thanks again for your assistance.
John
I'm wonder if perhaps this is an AuthKit/WebOb conflict.  It might be
that AuthKit is reading in the parameters of POST requests in such a
way that WebOb can't see them.  You could test by creating a POST form
with a simple controller, and seeing if the POST variables get
swallowed.  It isn't necessarily AuthKit that is swallowing them, but
it seems like a good chance (disabling AuthKit and testing would make
it clear).
Post by John Dickson
Hi folks
I've recently run into lots of problems with validation in an app of mine,
after upgrading to formencode 1.2.x.  This is a Pylons-based app (I've also
just upgraded Pylons from 0.9.6 to 0.9.7), which has been working fine for a
number of people until these upgrades.  I've been beating my head against a
brick wall trying to diagnose this for a couple of days now, and still
haven't got anywhere, so I'd be *really* grateful for any pointers you could
give.
I have to say, though, that I'm pretty much a newbie on formencode.  I'm
also also only guessing that this is a formencode issue, but it may well be
Pylons.
there are no errors detected by the decorator (using a subclass of Schema),
but if any validation failure occurs I get a KeyError when trying to run the
controller method to redisplay the form.  Examining the request, I see that
params, GET and POST are all empty (UnicodeMultiDict objects), while the
WSGI webob._parsed_post_vars variable seems to have all my POST fields in it
(exactly what I'd have expected to see in params).
I'm including a stack trace below, in case that's of any assistance.
Thanks
in advance for your help.
Cheers .................................... John Dickson
  File "/home/johnd/python/jcr-0.6.7/jcr/lib/base.py", line 98, in __call__
    return WSGIController.__call__(self, environ, start_response)
  File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py",
line 221, in __call__
    response = self._dispatch_call()
  File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py",
line 172, in _dispatch_call
    response = self._inspect_call(func)
  File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py",
line 107, in _inspect_call
    result = self._perform_call(func, args)
  File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py",
line 60, in _perform_call
    return func(**args)
  File "<string>", line 2, in upload
  File
"/usr/lib/python2.5/site-packages/AuthKit-0.4.3-py2.5.egg/authkit/authorize/pylons_adaptors.py",
line 36, in validate
    return permission.check(app, request.environ, self.start_response)
  File
"/usr/lib/python2.5/site-packages/AuthKit-0.4.3-py2.5.egg/authkit/permissions.py",
line 177, in check
    return app(environ, start_response)
  File
"/usr/lib/python2.5/site-packages/AuthKit-0.4.3-py2.5.egg/authkit/authorize/pylons_adaptors.py",
line 35, in app
    return func(self, *args, **kwargs)
  File "<string>", line 2, in upload
  File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/decorators/__init__.py",
line 161, in wrapper
    response = self._dispatch_call()
  File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py",
line 172, in _dispatch_call
    response = self._inspect_call(func)
  File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py",
line 107, in _inspect_call
    result = self._perform_call(func, args)
  File
"/usr/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py",
line 60, in _perform_call
    return func(**args)
  File "<string>", line 2, in index
  File
"/usr/lib/python2.5/site-packages/AuthKit-0.4.3-py2.5.egg/authkit/authorize/pylons_adaptors.py",
line 36, in validate
    return permission.check(app, request.environ, self.start_response)
  File
"/usr/lib/python2.5/site-packages/AuthKit-0.4.3-py2.5.egg/authkit/permissions.py",
line 177, in check
    return app(environ, start_response)
  File
"/usr/lib/python2.5/site-packages/AuthKit-0.4.3-py2.5.egg/authkit/authorize/pylons_adaptors.py",
line 35, in app
    return func(self, *args, **kwargs)
  File
"/home/johnd/python/jcr-0.6.7/jcr/controllers/projectadmin/selectfileset.py",
line 52, in index
    c.projectId = int(request.params['projectId'])
  File "build/bdist.linux-i686/egg/webob/multidict.py", line 314, in
__getitem__
    return
self._decode_value(self.multi.__getitem__(self._encode_key(key)))
  File "build/bdist.linux-i686/egg/webob/multidict.py", line 440, in
__getitem__
    raise KeyError(key)
KeyError: 'projectId'
------------------------------------------------------------------------------
_______________________________________________
FormEncode-discuss mailing list
https://lists.sourceforge.net/lists/listinfo/formencode-discuss
--
Ian Bicking  |  http://blog.ianbicking.org
--
   /Angle-parked in a parallel universe.../
--
Ian Bicking | http://blog.ianbicking.org
Loading...