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

Formatter server crashes with bundled libs on Python 3.11 #67

Closed
Bobronium opened this issue May 29, 2022 · 7 comments · Fixed by #141
Closed

Formatter server crashes with bundled libs on Python 3.11 #67

Bobronium opened this issue May 29, 2022 · 7 comments · Fixed by #141
Labels
bug Issue identified by VS Code Team member as probable bug needs investigation

Comments

@Bobronium
Copy link

Bobronium commented May 29, 2022

Steps to reproduce

  1. Make sure extension uses Python3.11
  2. Open python project without pydantic installed
  3. Observe server crash

Reason

Bundled version of pydantic is outdated, doesn't officialy support python 3.10 and crashes on 3.11
https://github.com/samuelcolvin/pydantic/pull/2885/files#diff-75ec66ee30c88591d87f430102cfbba45e2e0e31a50df8ab4862f03edc6d4072R237

Solution

  • add pydantic to the requirements
    or
  • fix version of pydantic installed with pygils (in pygils repo)
Formatter Name: Black
Formatter Module: black
Traceback (most recent call last):
  File "/Users/bobronium/.vscode/extensions/ms-python.black-formatter-2022.1.11451003/bundled/formatter/format_server.py", line 19, in <module>
    from pygls import lsp, protocol, server, uris, workspace
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bobronium/.vscode/extensions/ms-python.black-formatter-2022.1.11451003/bundled/libs/pygls/lsp/__init__.py", line 23, in <module>
    from pygls.lsp.types import *
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bobronium/.vscode/extensions/ms-python.black-formatter-2022.1.11451003/bundled/libs/pygls/lsp/types/__init__.py", line 2, in <module>
    from pygls.lsp.types.basic_structures import *
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bobronium/.vscode/extensions/ms-python.black-formatter-2022.1.11451003/bundled/libs/pygls/lsp/types/basic_structures.py", line 30, in <module>
    from pydantic import BaseModel, root_validator
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bobronium/.vscode/extensions/ms-python.black-formatter-2022.1.11451003/bundled/libs/pydantic/__init__.py", line 2, in <module>
    from . import dataclasses
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bobronium/.vscode/extensions/ms-python.black-formatter-2022.1.11451003/bundled/libs/pydantic/dataclasses.py", line 7, in <module>
    from .main import create_model, validate_model
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bobronium/.vscode/extensions/ms-python.black-formatter-2022.1.11451003/bundled/libs/pydantic/main.py", line 376, in <module>
    class BaseModel(Representation, metaclass=ModelMetaclass):
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bobronium/.vscode/extensions/ms-python.black-formatter-2022.1.11451003/bundled/libs/pydantic/main.py", line 369, in __new__
    cls.__signature__ = ClassAttribute('__signature__', generate_model_signature(cls.__init__, fields, config))
                                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bobronium/.vscode/extensions/ms-python.black-formatter-2022.1.11451003/bundled/libs/pydantic/utils.py", line 235, in generate_model_signature
    if config.extra is config.extra.allow:
                       ^^^^^^^^^^^^^^^^^^
  File "/Users/bobronium/.pyenv/versions/3.11.0a7/lib/python3.11/enum.py", line 169, in __get__
    raise AttributeError(
    ^^^^^^^^^^^^^^^^^^^^^
AttributeError: <enum 'Extra'> member has no attribute 'allow'
[Info  - 1:30:39 PM] Connection to server got closed. Server will restart.
@karthiknadig
Copy link
Member

@Bobronium The crash looks like it happens in python 3.11.0a7 not python 3.10, based on the last line in the trace:

  File "/Users/bobronium/.pyenv/versions/3.11.0a7/lib/python3.11/enum.py", line 169, in __get__
    raise AttributeError(
    ^^^^^^^^^^^^^^^^^^^^^

@Bobronium
Copy link
Author

Bobronium commented May 29, 2022

Nice catch! I forgot I had it installed. Though I believe same thing would happen in 3.10.

(In fact it already happened to me prior to installing 3.11)

@karthiknadig
Copy link
Member

Thanks for fling a bug on pygls this has to be handled there. Will keep this open to update when the issue is addressed on pygls.

@karthiknadig
Copy link
Member

@Bobronium I just verified that we run the tests on python 3.10.4:
https://github.com/microsoft/vscode-black-formatter/runs/6581108837?check_suite_focus=true#step:8:17

Can you provide more details on the 3.10 specific crash?

@Bobronium
Copy link
Author

Oh. I've double checked and it's indeed doesn't produce an error. Sorry for misinformation.

I assumed extension didn't crash in my other projects because I had never version of pydantic installed and extension did pick it up from projects PYTHONPATH, but turns out it doesn't crash without pydantic too when using python3.10.

@Bobronium Bobronium changed the title Formatter server crashes with bundled libs on Python 3.10 Formatter server crashes with bundled libs on Python 3.11 May 30, 2022
@karthiknadig karthiknadig added bug Issue identified by VS Code Team member as probable bug needs investigation and removed triage-needed Issue is not triaged. labels May 31, 2022
@taranlu-houzz
Copy link

taranlu-houzz commented Oct 14, 2022

Not sure if it's related, but the extension is also crashing for me on a project where my venv is using Python 3.11.0rc2. I always get a little popup like this:
image

I have black installed in the venv and am able to run it manually just fine.

@karthiknadig
Copy link
Member

This is related the 3.11 issue. you can look at Output > black formatter and see the details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug needs investigation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants