pallets / flask

The Python micro framework for building web applications.

Home Page:https://flask.palletsprojects.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Flask 3.0.1 breaks path-separated command line arguments

alexrudy opened this issue · comments

In a minimal flask app, running flask run --extra-files= or using any other argument that internally uses SeparatedPathType results in TypeError: super(type, obj): obj must be an instance or subtype of type

  1. Create a minimal flask application (follow the Quickstart).
  2. Install flask==3.0.1 (this bug is not reproducible with 3.0.0 AFAIK)
  3. Run flask run --extra-files=a

Expected Behavior:
The server should start up.

Actual Behavior:
The command raises a Type Error and exits with code 1

Full Traceback
Traceback (most recent call last):
  File ".../flask-cli-bug/..venv/bin/flask", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File ".../flask-cli-bug/..venv/lib/python3.11/site-packages/flask/cli.py", line 1105, in main
    cli.main()
  File ".../flask-cli-bug/..venv/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File ".../flask-cli-bug/..venv/lib/python3.11/site-packages/click/core.py", line 1686, in invoke
    sub_ctx = cmd.make_context(cmd_name, args, parent=ctx)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../flask-cli-bug/..venv/lib/python3.11/site-packages/click/core.py", line 943, in make_context
    self.parse_args(ctx, args)
  File ".../flask-cli-bug/..venv/lib/python3.11/site-packages/click/core.py", line 1408, in parse_args
    value, args = param.handle_parse_result(ctx, opts, args)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../flask-cli-bug/..venv/lib/python3.11/site-packages/click/core.py", line 2400, in handle_parse_result
    value = self.process_value(ctx, value)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../flask-cli-bug/..venv/lib/python3.11/site-packages/click/core.py", line 2356, in process_value
    value = self.type_cast_value(ctx, value)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../flask-cli-bug/..venv/lib/python3.11/site-packages/click/core.py", line 2344, in type_cast_value
    return convert(value)
           ^^^^^^^^^^^^^^
  File ".../flask-cli-bug/..venv/lib/python3.11/site-packages/click/core.py", line 2316, in convert
    return self.type(value, param=self, ctx=ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../flask-cli-bug/..venv/lib/python3.11/site-packages/click/types.py", line 83, in __call__
    return self.convert(value, param, ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../flask-cli-bug/..venv/lib/python3.11/site-packages/flask/cli.py", line 861, in convert
    return [super().convert(item, param, ctx) for item in items]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../flask-cli-bug/..venv/lib/python3.11/site-packages/flask/cli.py", line 861, in <listcomp>
    return [super().convert(item, param, ctx) for item in items]
            ^^^^^^^
TypeError: super(type, obj): obj must be an instance or subtype of type

Environment:

  • Python version: 3.11.6
  • Flask version: 3.0.1

Output from pip freeze:

blinker==1.7.0
click==8.1.7
Flask==3.0.1
itsdangerous==2.1.2
Jinja2==3.1.3
MarkupSafe==2.1.4
Werkzeug==3.0.1

Demo Repo: https://github.com/alexrudy/flask-3.0.1-cli-bug

I can confirm that this bug was introduced in 3.0.1. In our case, we're using the --exclude-patterns command line parameter.

versions

  • python 3.11.5
  • flask 3.0.1
  • click 8.1.7
  • ubuntu 22.04.1

command

flask --app app:start run --debug --exclude-patterns "*/tests/*:*/venv/*:*/temp/*"

traceback

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "<project>/venv/lib/python3.11/site-packages/flask/__main__.py", line 3, in <module>
    main()
  File "<project>/venv/lib/python3.11/site-packages/flask/cli.py", line 1105, in main
    cli.main()
  File "<project>/venv/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "<project>/venv/lib/python3.11/site-packages/click/core.py", line 1686, in invoke
    sub_ctx = cmd.make_context(cmd_name, args, parent=ctx)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<project>/venv/lib/python3.11/site-packages/click/core.py", line 943, in make_context
    self.parse_args(ctx, args)
  File "<project>/venv/lib/python3.11/site-packages/click/core.py", line 1408, in parse_args
    value, args = param.handle_parse_result(ctx, opts, args)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<project>/venv/lib/python3.11/site-packages/click/core.py", line 2400, in handle_parse_result
    value = self.process_value(ctx, value)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<project>/venv/lib/python3.11/site-packages/click/core.py", line 2356, in process_value
    value = self.type_cast_value(ctx, value)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<project>/venv/lib/python3.11/site-packages/click/core.py", line 2344, in type_cast_value
    return convert(value)
           ^^^^^^^^^^^^^^
  File "<project>/venv/lib/python3.11/site-packages/click/core.py", line 2316, in convert
    return self.type(value, param=self, ctx=ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<project>/venv/lib/python3.11/site-packages/click/types.py", line 83, in __call__
    return self.convert(value, param, ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<project>/venv/lib/python3.11/site-packages/flask/cli.py", line 861, in convert
    return [super().convert(item, param, ctx) for item in items]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<project>/venv/lib/python3.11/site-packages/flask/cli.py", line 861, in <listcomp>
    return [super().convert(item, param, ctx) for item in items]
            ^^^^^^^
TypeError: super(type, obj): obj must be an instance or subtype of type

Ah, this was because in Python 3.12, list comprehensions no longer execute in a separate hidden function scope. So no-arg super() became valid, which is what I saw when cleaning up things locally, but still didn't work on older Python versions.