Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flask 3.0.1 breaks path-separated command line arguments #5391

Closed
alexrudy opened this issue Jan 24, 2024 · 2 comments
Closed

Flask 3.0.1 breaks path-separated command line arguments #5391

alexrudy opened this issue Jan 24, 2024 · 2 comments
Milestone

Comments

@alexrudy
Copy link

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

@hofrob
Copy link

hofrob commented Jan 24, 2024

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

@davidism davidism added this to the 3.0.2 milestone Feb 3, 2024
@davidism
Copy link
Member

davidism commented Feb 3, 2024

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.

@davidism davidism closed this as completed Feb 3, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants