Expected Behavior
Sample Code
app = Flask(__name__)
@app.route("/", methods=["POST"])
def broke_behvior():
print(request.is_json)
rv = request.get_json(silent=True)
print(rv)
rv = request.get_json()
print(rv)
return "", 200
client = app.test_client()
client.post("/", data="'invalid json'")
Output
False
None
<Response streamed [400 BAD REQUEST]>
Actual Behavior
False
None
None
<Response streamed [200 OK]>
The fact that calling get_json with silent and then calling it without silent seems to break expected behavior. When I don't call silent I am depending on the exception being thrown, however, because the code caches even on error, you get this weird behavior.
While this might be expected behavior by the authors, the docs don't make this clear.
I would think, invalid json should not be cached, yet I can see the value of it, however, it adds an layer of uncertainty and therefore, I my opinion, is a bug.
Environment
- Python version: 3.4
- Flask version: 0.12.2
- Werkzeug version: 0.14.1
Expected Behavior
Sample Code
Output
Actual Behavior
The fact that calling
get_jsonwithsilentand then calling it withoutsilentseems to break expected behavior. When I don't callsilentI am depending on the exception being thrown, however, because the codecacheseven on error, you get this weird behavior.While this might be expected behavior by the authors, the docs don't make this clear.
I would think, invalid json should not be cached, yet I can see the value of it, however, it adds an layer of uncertainty and therefore, I my opinion, is a bug.
Environment