Re: [Mailman-Developers] Problem passing parameters to the REST API
On Jun 12, 2015, at 10:38 AM, khushboo surana wrote:
I have also changed the 'on_delete()' method of the mailman/rest/members.py file to retrieve the data sent.
I'd like to see the diff, or the modified function.
In the Core, I get the following logs:
Traceback (most recent call last): File "/usr/lib/python3.4/wsgiref/handlers.py", line 137, in run self.result = application(self.environ, self.start_response) File "/home/khushboo/gsoc/mailman/src/mailman/database/transaction.py", line 57, in wrapper rtn = function(*args, **kws) File "/home/khushboo/gsoc/mailman/src/mailman/rest/wsgiapp.py", line 65, in __call__ environ, start_response) File "/home/khushboo/gsoc/mailman/lib/python3.4/site-packages/falcon-0.3.0-py3.4.egg/falcon/api.py", line 182, in __call__ responder(req, resp, **params) TypeError: on_delete() missing 1 required positional argument: 'response'
Is that the entire traceback? I would have expected to see the on_delete() method mentioned there. There's probably a chained traceback in the log files before the one you pasted.
Be sure you don't change the signature of the on_delete() method. That must take exactly three arguments: self, request, and response. Normally, the way on_patch() or on_post() dig parameters out of the data is through a Validator() instance, which lists the parameters and their type conversion methods. You can see examples of this all over the rest submodule methods.
But on_delete() (really the HTTP DELETE method) doesn't accept any arguments since its purpose is to delete a resource.
I'm not sure what your best option is for recording the "mode" of the deletion. I'm not sure whether it's technically acceptable to add data to a DELETE method (the documentation and books I've consulted don't say either way). But it would definitely be out of the ordinary for Mailman's REST API. Even if it were acceptable, I think this on_delete() method would at least have to accept and do something reasonable with zero arguments (i.e. the mode would be optional).
Cheers, Barry
Hello!!
First of all I am sorry I did not not provide a lot of information (especially the diffs) in my previous mail that was required to get to the root of the problem. However, with the information Barry provided, I was able to make a few corrections to my code and now I am able to pass the mode of unsubscription as a parameter to the REST through the HTTP DELETE request.
On Fri, Jun 12, 2015 at 11:48 PM, Barry Warsaw <barry@list.org> wrote:
I'd like to see the diff, or the modified function.
Although it may not be required now, I am adding the link to my changes below. In case you need to see it to give further suggestions.
Mailman Core: https://github.com/khushboo9293/mailman/commit/d3e7b10da3f05357b6436ce2d9938...
Mailman Client: https://github.com/khushboo9293/mailman.client/commit/83397557f693f10b4a3f4d...
Be sure you don't change the signature of the on_delete() method. That must take exactly three arguments: self, request, and response. Normally, the way on_patch() or on_post() dig parameters out of the data is through a Validator() instance, which lists the parameters and their type conversion methods.
I hadn't changed the signature of the on_delete() method the method took 3 arguments only.Instead, I tried to pass the parameters in the body of DELETE request and used validator() to extract the data. But after cross checking with other examples in REST modules, I found a mistake in the way I was using validator and rectified it.
But on_delete() (really the HTTP DELETE method) doesn't accept any arguments since its purpose is to delete a resource.
I'm not sure what your best option is for recording the "mode" of the deletion. I'm not sure whether it's technically acceptable to add data to a DELETE method (the documentation and books I've consulted don't say either way).
As per what I had read, its is not forbidden to send data through a DELETE request but in many cases it is rejected or ignored by the server. In my case however, I am able to retrieve the data in the on_delete() method here and pass it to the model method unsubscribe(). Link to rest/members.py
Even if it were acceptable, I think this on_delete() method would at least have to accept and do something reasonable with zero arguments (i.e. the mode would be optional).
I have made changes in the REST code (rest/members.py) to make the mode optional. If the mode is not provided in the parameters, then the default mode would be assigned. Currently I don't know what the default mode of unsubsciption is, hence provided an arbitrary string.
Regards Khushboo
participants (2)
-
Barry Warsaw
-
khushboo surana