Skip to content

provide_automatic_options is weird #5916

Description

@davidism

While dealing with trying to detect duplicate routes in pallets/werkzeug#3105, I ran into an issue with Flask, which adds OPTIONS to every single rule by default.

I started looking into Flask's provide_automatic_options feature, and it's just weird.

  • Why is there a PROVIDE_AUTOMATIC_OPTIONS config? What benefit is there to turning OPTIONS off at all, let alone configuring it for a given deployment.
  • Flask adds OPTIONS to every route, then has a check that runs on dispatching every request to see if the method was OPTIONS and provide_automatic_options was enabled for the rule. Performing this check for every request seems wasteful, as opposed to adding an actual rule and endpoint so that the routing that's already happening handles it.
    • But adding a rule is also sort of bad, as it results in a bunch of duplicate rules since Flask has no way to know what other rules have already been added. This can be caught with Werkzeug 3.2, and doesn't cause problems in earlier versions, but it's still annoying.
  • provide_automatic_options can be set as an attribute on the view function. There are some other attributes that are barely documented as well, such as required_methods. This is presumably mostly for View classes, but works on functions too, making type annotations unhelpful.
  • If PROVIDE_AUTOMATIC_OPTIONS is disabled (not the default), the logic for the provide_automatic_options argument and attribute doesn't work correctly to enable it, it only works for disabling.
  • The tests for this were incomplete and had some issues. Some other tests were revealed to be adding duplicate rules as well.

At a minimum I've fixed the enabling issue. I've also got a change that registers a route and view for options instead of using special dispatch logic. We should also consider deprecating the config.

Activity

  1. added this to the 3.2.0 milestone on Feb 12, 2026
  2. self-assigned this
    on Feb 12, 2026
  3. davidism commented on Feb 12, 2026

    @davidism
    MemberAuthor

    The config was actually added quite recently, and it turns out we already had the discussion about whether the config made sense #5496

  4. locked as resolved and limited conversation to collaborators on Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions