Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix POST/PUT with querystring #261

Merged
merged 4 commits into from Nov 20, 2014
Merged

Fix POST/PUT with querystring #261

merged 4 commits into from Nov 20, 2014

Conversation

mindflayer
Copy link
Contributor

If you send a JSON body but your url contains querystring arguments, only JSON content will be returned.

@mindflayer
Copy link
Contributor Author

Example:

from flask import Flask
from flask.ext.restful import reqparse, Api, Resource

app = Flask(__name__)
api = Api(app)

class Bar(Resource):
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('foo')  # default argument location is ('json', 'values')
        parser.add_argument('baz')
        args = parser.parse_args()
        return args

api.add_resource(Bar, '/')
app.run()

Result:

$ curl -XPOST "http://127.0.0.1:5000/?foo=1" -d '{"baz":2}' -H "Content-Type: application/json"
{"foo": null, "baz": "2"}

Result with the patch:

$ curl -XPOST "http://127.0.0.1:5000/?foo=1" -d '{"baz":2}' -H "Content-Type: application/json"
{"foo": "1", "baz": "2"}

@mindflayer
Copy link
Contributor Author

Is this project abandoned?

@joshfriend
Copy link
Member

@mindflayer thanks for the fix. It looks like there are no tests that check that reqparse can actually pull arguments from two different sources. I tested your solution manually and it seems to be OK, but I'd love it if you could provide a test case that exercises the behavior you described in the above comments.

Testing both JSON and values location in a single request
@mindflayer
Copy link
Contributor Author

Here you are, @joshfriend ! 👍

joshfriend added a commit that referenced this pull request Nov 20, 2014
fixes not being able to extract args from multiple places with reqparse.
@joshfriend joshfriend merged commit 6812392 into flask-restful:master Nov 20, 2014
@joshfriend
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants