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

Instance of 'ManyToManyField' has no 'all' memberPylint E1101:(no-member) #404

Open
LCH-1 opened this issue Sep 13, 2023 · 5 comments
Open

Comments

@LCH-1
Copy link

LCH-1 commented Sep 13, 2023

models.py

from django.db import models


class Category(models.Model):
    name = models.CharField("name", max_length=100)


class Movie(models.Model):
    categories = models.ManyToManyField(Category, related_name="movies")
    created_at = models.DateTimeField("created_at", auto_now_add=True)

    def __str__(self):
        test = ""  # for just test
        return ""

    def get_categories(self):
        return self.categories.all()

    def get_created_date(self):
        return self.created_at.strftime("%Y-%m-%d")

pylint extention result

2023-09-13 18:33:10.721 [info] [Trace - 6:33:10 PM] Sending notification 'textDocument/didSave'.
2023-09-13 18:33:10.725 [info] [Trace - 6:33:10 PM] Received notification 'window/logMessage'.
2023-09-13 18:33:10.725 [info] c:\Users\user\Desktop\django_test\venv\Scripts\python.exe -m pylint --reports=n --output-format=json --disable=C0115, C0114, C0116 --load-plugins=pylint_django --django-settings-module=test_project.settings --clear-cache-post-run=y --from-stdin c:\Users\user\Desktop\django_test\testapp\models.py
2023-09-13 18:33:10.725 [info] [Trace - 6:33:10 PM] Received notification 'window/logMessage'.
2023-09-13 18:33:10.725 [info] CWD Linter: c:\Users\user\Desktop\django_test
2023-09-13 18:33:12.273 [info] [Trace - 6:33:12 PM] Received notification 'window/logMessage'.
2023-09-13 18:33:12.273 [info] file:///c%3A/Users/user/Desktop/django_test/testapp/models.py :
[
    {
        ...
        "type": "warning",
        "obj": "Movie.__str__",
        "symbol": "unused-variable",
        "message": "Unused variable 'test'",
        "message-id": "W0612"
    },
    {
        ...
        "type": "error",
        "obj": "Movie.get_categories",
        "symbol": "no-member",
        "message": "Instance of 'ManyToManyField' has no 'all' member",
        "message-id": "E1101"
    },
    {
        ...
        "type": "error",
        "obj": "Movie.get_created_date",
        "symbol": "no-member",
        "message": "Instance of 'DateTimeField' has no 'strftime' member",
        "message-id": "E1101"
    }
]

pylint terminal result

c:\Users\user\Desktop\django_test\venv\Scripts\python.exe -m pylint --reports=n --output-format=json --disable="C0115, C0114, C0116" --load-plugins=pylint_django --django-settings-module=test_project.settings --clear-cache-post-run=y c:\Users\user\Desktop\django_test\testapp\models.py

[
    {
        ...
        "type": "warning",
        "obj": "Movie.__str__",
        "symbol": "unused-variable",
        "message": "Unused variable 'test'",
        "message-id": "W0612"
    }
]

versions

Pylint(Vscode Extention) v2023.6.0
Python 3.11.1
Django==4.2.4
pylint==2.17.5
pylint-django==2.5.3
astroid==2.15.6
@LCH-1
Copy link
Author

LCH-1 commented Sep 13, 2023

this error does not occur in terminal, but only in vscode pylint extension.

@Pierre-Sassoulas
Copy link
Member

What are the versions used in the vscode extension ? You also need to check if you're in the same virtual environnement.

@LCH-1
Copy link
Author

LCH-1 commented Sep 13, 2023

More detailed results were reported in the first comment.

I also checked that the selected virtual environment settings are the same as terminal and vscode selected interpreter.

@poulposse
Copy link

Any progress? (Same issue here)

@sjdemartini
Copy link

I'm experiencing the same problem, but I'm guessing it's an issue with the VSCode Extension (https://github.com/microsoft/vscode-pylint) and perhaps not specific to pylint-django. Seemingly the VSCode extension is (as of recently) failing to load the pylint-django plugin properly, regardless of whether I specify it with the pylint.args setting or in my .pylintrc. I'm not sure where to dig in further.

For what it's worth, I do see this near the top of the VSCode Pylint logs:

2024-04-17 14:44:36.710 [info] [Error - 2:44:36 PM] Traceback (most recent call last):
  File "<frozen runpy>", line 148, in _get_module_details
  File "<frozen runpy>", line 142, in _get_module_details
ImportError: No module named pylint.__main__

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/sdemartini/.vscode/extensions/ms-python.pylint-2023.10.1/bundled/tool/lsp_server.py", line 770, in _run_tool_on_document
    result = utils.run_module(
             ^^^^^^^^^^^^^^^^^
  File "/Users/sdemartini/.vscode/extensions/ms-python.pylint-2023.10.1/bundled/tool/lsp_utils.py", line 208, in run_module
    return _run_module(module, argv, use_stdin, source)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sdemartini/.vscode/extensions/ms-python.pylint-2023.10.1/bundled/tool/lsp_utils.py", line 193, in _run_module
    runpy.run_module(module, run_name="__main__")
  File "<frozen runpy>", line 222, in run_module
  File "<frozen runpy>", line 152, in _get_module_details
ImportError: No module named pylint.__main__; 'pylint' is a package and cannot be directly executed

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

4 participants