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

pydantic throws ValidationError #243

Closed
slackline opened this issue Jun 29, 2022 · 5 comments
Closed

pydantic throws ValidationError #243

slackline opened this issue Jun 29, 2022 · 5 comments

Comments

@slackline
Copy link

I've encountered an error that pydantic has with pygls when used by jedi-language-server...

  File "/home/neil/.local/lib/python3.9/site-packages/pygls/protocol.py", line 152, in deserialize_message
    deserialize_params(data, get_params_type)
  File "/home/neil/.local/lib/python3.9/site-packages/pygls/protocol.py", line 138, in deserialize_params
    data['params'] = params_type(**params)
  File "pydantic/main.py", line 406, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for InitializeParams
processId
  value is not a valid integer (type=type_error.integer)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/neil/.local/bin/jedi-language-server", line 8, in <module>
    sys.exit(cli())
  File "/home/neil/.local/lib/python3.9/site-packages/jedi_language_server/cli.py", line 125, in cli
    SERVER.start_io()
  File "/home/neil/.local/lib/python3.9/site-packages/pygls/server.py", line 204, in start_io
    self.loop.run_until_complete(
  File "/usr/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
    return future.result()
  File "/home/neil/.local/lib/python3.9/site-packages/pygls/server.py", line 75, in aio_readline
    proxy(b''.join(message))
  File "/home/neil/.local/lib/python3.9/site-packages/pygls/protocol.py", line 456, in data_received
    json.loads(body.decode(self.CHARSET),
  File "/usr/lib/python3.9/json/__init__.py", line 359, in loads
    return cls(**kw).decode(s)
  File "/usr/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.9/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
  File "/home/neil/.local/lib/python3.9/site-packages/pygls/protocol.py", line 154, in deserialize_message
    raise JsonRpcInvalidParams()
pygls.exceptions.JsonRpcInvalidParams: Invalid Params

The authors of jedi-language-server suggested it might be down to lsp-jedi who suggested it might be down to jedi-language-server, but the error appeares to stem from pygls and its use of pydantic (from my crude reading).

This is with the following versions installed under user account rather than virtualenv

❱ pip show pygls pydantic jedi-language-server         
Name: pygls
Version: 0.11.3
Summary: a pythonic generic language server (pronounced like "pie glass").
Home-page: https://github.com/openlawlibrary/pygls/tree/master/
Author: Open Law Library
Author-email: info@openlawlib.org
License: Apache 2.0
Location: /home/neil/.local/lib/python3.9/site-packages
Requires: pydantic, typeguard
Required-by: jedi-language-server
---
Name: pydantic
Version: 1.8.2
Summary: Data validation and settings management using python 3.6 type hinting
Home-page: https://github.com/samuelcolvin/pydantic
Author: Samuel Colvin
Author-email: s@muelcolvin.com
License: MIT
Location: /home/neil/.local/lib/python3.9/site-packages
Requires: typing-extensions
Required-by: jedi-language-server, pygls
---
Name: jedi-language-server
Version: 0.36.0
Summary: A language server for Jedi!
Home-page: https://github.com/pappasam/jedi-language-server
Author: Sam Roeca
Author-email: samuel.roeca@gmail.com
License: MIT
Location: /home/neil/.local/lib/python3.9/site-packages
Requires: docstring-to-markdown, jedi, pydantic, pygls
Required-by: 

If there is any more useful information or steps I can take to help with investigating and resolving this please let me know.

@dimbleby
Copy link
Contributor

dimbleby commented Jun 30, 2022

pydantic.error_wrappers.ValidationError: 1 validation error for InitializeParams
processId
  value is not a valid integer (type=type_error.integer)

This assertion is the server claiming that the client is sending a bad message (specifically: a non-integer process ID).

You will need to get trace showing the message, and compare it with what the LSP specification says is allowed. I'm not an emacs user but I expect that its LSP client has some sort of setting to log the protocol flows.

Then you can either agree with the server that the client is sending a bad message - in which case raise the issue at the client; or you can disagree, in which case raise the issue at the server.

@slackline
Copy link
Author

Thanks for the pointers, I'll try and get a trace out and work out where the problem is occurring.

@tombh
Copy link
Collaborator

tombh commented Dec 3, 2022

Pygls has now migrated to lsprotocol, so no longer depends on Pydantic. lsprotocol itseslf uses https://github.com/python-attrs/cattrs

@tombh tombh closed this as completed Dec 3, 2022
@slackline
Copy link
Author

Thank you @tombh very much appreciated.

@tombh
Copy link
Collaborator

tombh commented Dec 3, 2022

Our pleasure 🙇 The greater thanks goes to @alcarney in particular for the migration itself. And Brett and Karthik from Microsoft too ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants