0

When I reference the params parameter of the WebOb Request an element is suddenly popped off the end. That or it's being reduced to a single element. The referenced element isn't the one getting knocked off.

if req.str_params.has_key('method'):
   req.method = req.str_params.getone('method')

Before this line logging turns up:

DEBUG:root:NestedMultiDict([('method', 'put'), ('name', 'some_name')])

after:

DEBUG:root:NestedMultiDict([('method', 'put')])

I'm at a loss.

Matt
  • 1,062
  • 11
  • 21
  • Works fine if I copy req.params to another var then use that later on, but this seems super silly. – Matt May 23 '11 at 23:40
  • Very odd, then -- that's only creating another reference to the same object, not making a deep copy – Cameron May 24 '11 at 00:00
  • Right, I don't understand it. Something hinky is afoot. – Matt May 24 '11 at 00:03
  • Check the way it's being logged -- I looked in the source for NestedMultiDict and `getone` really shouldn't cause any modifications such as this. Write a unit test and see if you can reproduce it there -- if not, it's likely a subtlety of your own code causing this bug – Cameron May 24 '11 at 01:46

1 Answers1

2

This is because you are setting req.method. Probably name=some_name is in the body of the request, and so long as req.method == 'POST' you'll get that parameter back. The moment you change the method to PUT you're keeping WebOb from parsing the request body (request bodies are expected to be entities, not HTML form inputs). This is calculated when you get the attribute req.str_params, so by saving a reference to the params you are avoiding the req.method check.

Ian Bicking
  • 9,762
  • 6
  • 33
  • 32