Answer a JSON body that is not an object with a 400 in formdata()

formdata() adds the fields of a JSON body to the dictionary it returns,
and assumed that the body was an object. A client could send any other
JSON value:

- A number, a string, true, false or null made dict.update() fail, and
  the request was a 500.
- A list of pairs, such as [["a", 1]] or ["ab"], was taken to be
  fields, and an empty list was taken to be no fields.

Raise werkzeug's BadRequest for a JSON body that is not an object, so
that the response is a 400, as it already is for a body that is not
JSON at all. The endpoint may catch it.

Document JSON bodies, and the order in which the query string, the form
and the JSON object are merged, in docs/forms.md.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016kvsehZiEBaV3mdKkiTU3C
4 files changed
tree: 82071658d81eeb0e328038256992b0fe3a5022ff
  1. .github/
  2. docs/
  3. examples/
  4. src/
  5. tests/
  6. .asf.yaml
  7. .gitignore
  8. CHANGELOG.md
  9. LICENSE
  10. Makefile
  11. pyproject.toml
  12. README.md
  13. setup.cfg
  14. uv.lock
README.md

asfquart - a Quart framework for the ASF

This is a Quart framework for ASF web applications.

On top of Quart, this package layers a lot of functionality, much of which is specific to the ASF and its infrastructure and preferred approaches for website application development.

asfquart adds the following items to basic quart:

  • simple construction of the APP
  • default config.yaml
  • watching the .py and config for changes, to cause a restart/reload
  • watch SIGINT to halt and SIGUSR2 to restart/reload
  • template watching and rendering for EZT templates
  • URL path routing for pages and API endpoints
  • Oauth with our ASF provider for authn
  • LDAP group testing for authz
  • long-running tasks and their lifecycle management

Current (known, public) users of asfquart:

Future users of asfquart:

Primer

See the documentation page for more information.

import asfquart
from asfquart.auth import Requirements as R

def my_app() -> asfquart.base.QuartApp:
    # Construct the quart service. By default, the oauth gateway is enabled at /oauth.
    app = asfquart.construct("my_app_service")

    @app.route("/")
    async def homepage():
        return "Hello!"

    @app.route("/secret")
    @asfquart.auth.require(R.committer)
    async def secret_page():
      return "Secret stuff!"

    return app

if __name__ == "__main__":
    app = my_app()

    # Run the application in an extended debug mode:
    #  - reload the app when any source / config file get changed
    app.runx(port=8000)
else:
    # Serve the application via an ASGI server, e.g. hypercorn
    app = my_app()

An asfquart application runs as one process. Serve it with one worker, and run one instance of it. Logins in progress and the application secret are not shared between processes, so more than one worker, or several instances behind a load balancer, will fail in ways that are hard to see. One process explains what assumes this, and what would have to change to lift it.

Installation

Create and activate a virtual environment and then install asfquart using uv or pip:

# With uv
uv add asfquart

# With uv pip-compatible interface
uv pip install asfquart

# With standard pip
pip install asfquart

Note: Adding the [aioldap] extra will install optional dependencies for LDAP support that will require additional system dependencies:

# With uv
uv add asfquart --extra aioldap

# With uv pip-compatible interface
uv pip install "asfquart[aioldap]"

# With standard pip
pip install "asfquart[aioldap]"

Development

Install development environment

Install the required dependencies for development:

uv sync

Install the optional dependencies for development:

uv sync --extra aioldap

Building asfquart package

Running the tests:

uv sync --all-extras --group test

uv run pytest

Building the package:

uv build

Examples

There is a simple test application included (./examples/snippets/simple_app.py) to outline the basic setup. To run the application in development mode, type:

make example-dev

to run it with an ASGI server for production, type:

make example-run