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

AstroidImportError when ForeignKey points to app not in root module #233

Closed
federicobond opened this issue Apr 29, 2019 · 2 comments
Closed

Comments

@federicobond
Copy link
Contributor

I have a project structure where Django apps live in an apps/ directory. This makes the import path for a model at apps.myapp.models.MyModel.

When pylint_django processes the ForeignKey, it tries to load myapp.models, resulting in an astroid.exceptions.AstroidImportError. The only way around it as I see is to actually read the contents of INSTALLED_APPS settings variable.

@mikalai-mitsin
Copy link

mikalai-mitsin commented May 3, 2019

+

@atodorov
Copy link
Contributor

I'm seeing the same issue but there's no reliable way to get this information from Django's INSTALLED_APPS. Applications can define an AppConfig class and have a name different from their actual Python module. On top of this Django requires the format for foreign keys to be "app_name.ModelName" and you can't have dots in the app_name while I have a project where AppConfig uses dots in the app_name.

The solution is to modify the PYTHONPATH variable and instruct pylint where to find these additional modules:

$ PYTHONPATH=~/Kiwi/tcms/ pylint --load-plugins pylint_django tcms/testplans/models.py

My ForeignKey relations look like ForeignKey('management.Tag') while the module is tcms.management.models

atodorov added a commit to kiwitcms/Kiwi that referenced this issue May 10, 2019
samy-aitouakli pushed a commit to openfun/joanie that referenced this issue Aug 18, 2023
Add the env variable PYTHONPATH to circleci config to allow pylint
to find some models, avoiding crashes

pylint-dev/pylint-django#233
samy-aitouakli pushed a commit to openfun/joanie that referenced this issue Aug 18, 2023
Add the env variable PYTHONPATH to circleci config to allow pylint
to find some models, avoiding crashes

pylint-dev/pylint-django#233
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