question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pydantic throws ValidationError

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
dimblebycommented, 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.

1reaction
tombhcommented, Dec 3, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to prevent Pydantic from throwing an exception on ...
This is a complete script with a new class BaseModelNoException that inherits Pydantic's BaseModel, wraps the exception ValidationError and ...
Read more >
Python Examples of pydantic.ValidationError
This page shows Python examples of pydantic.ValidationError. ... JWTError, ValidationError): raise HTTPException( status_code=status.
Read more >
Validators - pydantic
Custom validation and complex relationships between objects can be achieved using the validator decorator. Python 3.7 and above. from pydantic import BaseModel ...
Read more >
Exception handling during validation · Issue #3915 · pydantic ...
from pydantic import BaseSettings, validator class OtherCfg(BaseSettings): ... where even a KeyError is thrown and the program crashes with.
Read more >
How we validate input data using pydantic
Pydantic raises a ValidationError when the validation of the model fails, stating which field, i.e. attribute, raised the error and why.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found