Repository navigation
Milestone
Description
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_OPTIONSconfig? What benefit is there to turningOPTIONSoff at all, let alone configuring it for a given deployment. - Flask adds
OPTIONSto every route, then has a check that runs on dispatching every request to see if the method wasOPTIONSandprovide_automatic_optionswas 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_optionscan be set as an attribute on the view function. There are some other attributes that are barely documented as well, such asrequired_methods. This is presumably mostly forViewclasses, but works on functions too, making type annotations unhelpful.- If
PROVIDE_AUTOMATIC_OPTIONSis disabled (not the default), the logic for theprovide_automatic_optionsargument 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.
Metadata
Metadata
Assignees
Labels
No labels
Activity
davidism commentedon Feb 12, 2026
The config was actually added quite recently, and it turns out we already had the discussion about whether the config made sense #5496