Skip to content

BadRequestKeyError no longer contains the missing key from self.form as of 1.0.3 #3249

@Roguelazer

Description

@Roguelazer

Expected Behavior

When self.form is indexed with a key that isn't present, BadRequestKeyError is raised. Under 1.0.2 and below, the .args property of this exception contained the actual missing key -- great for lightweight error presentation.

Minimal demonstration:

from flask import Flask, jsonify, request
from werkzeug.exceptions import BadRequestKeyError

app = Flask('test')

@app.errorhandler(BadRequestKeyError)
def bad_key(e):
    return jsonify({'missing key(s)': e.args})


@app.route('/')
def root():
    return request.form['foo']

app.run()

Under 1.0.2 and below we see the following behavior:

 % curl localhost:5000
{"missing key(s)":["foo"]}

Under 1.0.3:

% curl localhost:5000
{"missing key(s)":[]}

This occurs independent of $FLASK_DEBUG

Actual Behavior

There appears to be no way to get at the missing key from an error handler.

Environment

  • Python version: 3.6.6
  • Flask version: 1.0.3
  • Werkzeug version: 0.15.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions