jucacrispim / pylint-mongoengine

Pylint plugin to handle mongoengine stuff
GNU General Public License v3.0
15 stars 6 forks source link

Crash: Astriod error when dynamically referencing in Pydantic #16

Closed edwinjosegeorge closed 1 year ago

edwinjosegeorge commented 1 year ago

Re-reporting from Pylint issue

Bug description

"""
Mixed use of pydantic with mongoengine that raises
astroid.exceptions.InferenceError: StopIteration raised without any error information.
"""

from mongoengine import Document
from pydantic import BaseModel

class Users(Document):  # pylint: disable=too-few-public-methods
    """A mongoengine document model"""

class UsersPydantic(BaseModel):  # pylint: disable=too-few-public-methods
    """Pydantic Base Model"""
    type_: Users

    def get_value(self) -> Users:
        """get some document"""
        return self.type_.objects()[0]

    class Config:  # pylint: disable=too-few-public-methods
        """update meta details"""
        arbitrary_types_allowed = True

Configuration

[MAIN]
extension-pkg-whitelist=pydantic, mongoengine
load-plugins=pylint_pydantic, pylint_mongoengine

Command used

pylint my_code.py

Pylint output

pylint crashed with a ``AstroidError`` and with the following stacktrace:

Traceback (most recent call last):
  File "my_repo/virtuals/lib/python3.10/site-packages/astroid/decorators.py", line 140, in raise_if_nothing_inferred
    yield next(generator)
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "my_repo/virtuals/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 790, in _lint_file
    check_astroid_module(module)
  File "my_repo/virtuals/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 1060, in check_astroid_module
    retval = self._check_astroid_module(
  File "my_repo/virtuals/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 1110, in _check_astroid_module
    walker.walk(node)
  File "my_repo/virtuals/lib/python3.10/site-packages/pylint/utils/ast_walker.py", line 93, in walk
    self.walk(child)
  File "my_repo/virtuals/lib/python3.10/site-packages/pylint/utils/ast_walker.py", line 93, in walk
    self.walk(child)
  File "my_repo/virtuals/lib/python3.10/site-packages/pylint/utils/ast_walker.py", line 93, in walk
    self.walk(child)
  [Previous line repeated 3 more times]
  File "my_repo/virtuals/lib/python3.10/site-packages/pylint/utils/ast_walker.py", line 90, in walk
    callback(astroid)
  File "my_repo/virtuals/lib/python3.10/site-packages/pylint_plugin_utils/__init__.py", line 60, in __call__
    self.augmentation_func(Chain(self.old_method, node), node)
  File "my_repo/virtuals/lib/python3.10/site-packages/pylint_plugin_utils/__init__.py", line 117, in __call__
    if self.test_func(node):
  File "my_repo/virtuals/lib/python3.10/site-packages/pylint_mongoengine/utils.py", line 115, in node_is_default_qs
    for cls in base_cls.inferred():
  File "my_repo/virtuals/lib/python3.10/site-packages/astroid/nodes/node_ng.py", line 611, in inferred
    return list(self.infer())
  File "my_repo/virtuals/lib/python3.10/site-packages/astroid/nodes/node_ng.py", line 169, in infer
    yield from self._infer(context=context, **kwargs)
  File "my_repo/virtuals/lib/python3.10/site-packages/astroid/decorators.py", line 146, in raise_if_nothing_inferred
    raise InferenceError(
astroid.exceptions.InferenceError: StopIteration raised without any error information.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "my_repo/virtuals/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 755, in _lint_files
    self._lint_file(fileitem, module, check_astroid_module)
  File "my_repo/virtuals/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 792, in _lint_file
    raise astroid.AstroidError from e
astroid.exceptions.AstroidError

Expected behavior

Pylint exits peacefully!

Pylint version

pylint 2.15.9
astroid 2.12.13
Python 3.10.8 (main, Oct 21 2022, 22:22:30) [Clang 14.0.0 (clang-1400.0.29.202)]

OS / Environment

No response

Additional dependencies

pylint-mongoengine==0.4.0 pylint-plugin-utils==0.7 pylint-pydantic==0.1.4 pydantic==1.10.4 mongoengine==0.25.0

jucacrispim commented 1 year ago

Hi @edwinjosegeorge .

Thank you very much. It's fixed and a new version was release to pypi. pylint-mongoengine==0.5.0