pallets / quart

An async Python micro framework for building web applications.
https://quart.palletsprojects.com
MIT License
3.01k stars 164 forks source link

Error of type KeyError: 'PROVIDE_AUTOMATIC_OPTIONS' when using factory #379

Closed antonpetrov145 closed 5 days ago

antonpetrov145 commented 5 days ago

Here is what I use to instantiate the quest app in factory:

from quart import Quart

def create_app():
    app = Quart(__name__)
    return app

app = create_app()
if __name__ == "__main__":
    app.run(host='0.0.0.0')

When I do this I receive error like this

File "/home/anton/.pyenv/versions/3.9.17/envs/uploader_venv/lib/python3.9/site-packages/flask/sansio/app.py", line 641, in add_url_rule
    if "OPTIONS" not in methods and self.config["PROVIDE_AUTOMATIC_OPTIONS"]:
KeyError: 'PROVIDE_AUTOMATIC_OPTIONS'

Expected Behavior - Quart app starts normally

Actual behavior - error on creating the app object

Proposed solution: As you can see I don't have config object thus no config is provided. After taking a look in the app code in Quart, the line that throws the error is

 if provide_automatic_options is None:
      if "OPTIONS" not in methods and self.config["PROVIDE_AUTOMATIC_OPTIONS"]:
          provide_automatic_options = True
          required_methods.add("OPTIONS")
      else:
          provide_automatic_options = False

To handle the missing config object

try:
      if provide_automatic_options is None:
          if "OPTIONS" not in methods and self.config["PROVIDE_AUTOMATIC_OPTIONS"]:
              provide_automatic_options = True
              required_methods.add("OPTIONS")
          else:
              provide_automatic_options = False
except Exception:
    provide_automatic_options = False

Environment:

If I'm mistaken with anything please let me know. Thanks

develerltd commented 5 days ago

Duplicate of https://github.com/pallets/quart/issues/371

davidism commented 5 days ago

Quart 0.19.9 is now available on PyPI.