-
-
Notifications
You must be signed in to change notification settings - Fork 485
Error importing plugin 'mypy_django_plugin.main' #166
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
Comments
Please check what the exact error is (need to patch/debug mypy; see python/mypy#7512). |
On Tue, Sep 17, 2019 at 01:36:49AM -0700, Daniel Hahler wrote:
> ../mypy.ini:12: error: Error importing plugin 'mypy_django_plugin.main'
Please check what the exact error is (need to patch/debug mypy; see python/mypy#7512).
Oh boy, they sure don't make it easy to find out what happened...
So, the error is:
```
../mypy.ini:12: error: Error importing plugin 'mypy_django_plugin.main': Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
```
which I understand, *but*, I do have this in mypy.ini too, as prescribed
by documentation:
```
[mypy.plugins.django-stubs]
django_settings_module = path.to.a.module.of.mine
```
and the module in question is already used for django testing by pytest,
where it works properly.
What am I missing?
(thanks a lot for your help btw)
|
Try exporting
Are you running |
On Tue, Sep 17, 2019 at 02:02:42AM -0700, Daniel Hahler wrote:
Try exporting `DJANGO_SETTINGS_MODULE` additionally.
That was it. Was it supposed to read the doc without it too, though?
(I can patch my workflow to export the variable in this specific case,
no big deal, just trying to understand what would be the expected
behavior here.)
Are you running `mypy` directly or through some pytest plugin?
Directly.
pytest is run separately. I've mentioned it just as validation that the
module in question is a valid/working django setting module.
|
It should not be necessary to export it. (#153 is a way to only use the exported env.) So it looks something is setting up Django during import time likely for you. |
On Tue, Sep 17, 2019 at 04:14:25AM -0700, Daniel Hahler wrote:
It should not be necessary to export it. (#153 is a way to only use the exported env.)
So it looks something is setting up Django during import time likely for you.
The traceback would be useful therefore.
Here it is:
```
Traceback (most recent call last):
File "/my/home/dir/.virtualenvs/swh/bin/mypy", line 10, in <module>
sys.exit(console_entry())
File "/my/home/dir/.virtualenvs/swh/lib/python3.7/site-packages/mypy/__main__.py", line 8, in console_entry
main(None, sys.stdout, sys.stderr)
File "/my/home/dir/.virtualenvs/swh/lib/python3.7/site-packages/mypy/main.py", line 83, in main
res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
File "/my/home/dir/.virtualenvs/swh/lib/python3.7/site-packages/mypy/build.py", line 164, in build
result = _build(sources, options, alt_lib_path, flush_errors, fscache, stdout, stderr)
File "/my/home/dir/.virtualenvs/swh/lib/python3.7/site-packages/mypy/build.py", line 202, in _build
plugin, snapshot = load_plugins(options, errors, stdout)
File "/my/home/dir/.virtualenvs/swh/lib/python3.7/site-packages/mypy/build.py", line 380, in load_plugins
raise exc
File "/my/home/dir/.virtualenvs/swh/lib/python3.7/site-packages/mypy/build.py", line 378, in load_plugins
module = importlib.import_module(module_name)
File "/my/home/dir/.virtualenvs/swh/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/my/home/dir/.virtualenvs/swh/lib/python3.7/site-packages/mypy_django_plugin/main.py", line 14, in <module>
from mypy_django_plugin.django.context import DjangoContext
File "/my/home/dir/.virtualenvs/swh/lib/python3.7/site-packages/mypy_django_plugin/django/context.py", line 19, in <module>
from django.contrib.postgres.fields import ArrayField
File "/my/home/dir/.virtualenvs/swh/lib/python3.7/site-packages/django/contrib/postgres/fields/__init__.py", line 1, in <module>
from .array import * # NOQA
File "/my/home/dir/.virtualenvs/swh/lib/python3.7/site-packages/django/contrib/postgres/fields/array.py", line 3, in <module>
from django.contrib.postgres import lookups
File "/my/home/dir/.virtualenvs/swh/lib/python3.7/site-packages/django/contrib/postgres/lookups.py", line 4, in <module>
from .search import SearchVector, SearchVectorExact, SearchVectorField
File "/my/home/dir/.virtualenvs/swh/lib/python3.7/site-packages/django/contrib/postgres/search.py", line 47, in <module>
class SearchVector(SearchVectorCombinable, Func):
File "/my/home/dir/.virtualenvs/swh/lib/python3.7/site-packages/django/contrib/postgres/search.py", line 50, in SearchVector
_output_field = SearchVectorField()
File "/my/home/dir/.virtualenvs/swh/lib/python3.7/site-packages/django/db/models/fields/__init__.py", line 172, in __init__
self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
File "/my/home/dir/.virtualenvs/swh/lib/python3.7/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/my/home/dir/.virtualenvs/swh/lib/python3.7/site-packages/django/conf/__init__.py", line 39, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
```
|
@zacchiro please fix the formatting. |
Appears to be triggered via:
Without investigating it looks like the plugin's setting up of Django should happen before this already then. @zacchiro |
On Tue, Sep 17, 2019 at 05:35:58AM -0700, Daniel Hahler wrote:
@zacchiro please fix the formatting.
I've no idea why it isn't been rendered as preformatted text as
usual. The markdown looks correct to me.
On Tue, Sep 17, 2019 at 05:38:22AM -0700, Daniel Hahler wrote:
Appears to be triggered via:
```
File "/my/home/dir/.virtualenvs/swh/lib/python3.7/site-packages/mypy_django_plugin/main.py", line 14, in <module>
from mypy_django_plugin.django.context import DjangoContext
```
Without investigating it looks like the plugin's setting up of Django
should happen before this already then.
@zacchiro
What Django version is this?
1.11.23
|
was facing the same issue, but placing |
I think that just make you not load the plugin at all, because then the |
I am having the same issue, and adding Not sure how to proceed. |
I'm able to repro this in Django v2 as well. This happens at module import time, before the An example of this is here: master...sklarsa:issue-166 |
This issue is quite outdated. Gonna close it, feel free to reopen if it's still a relevant problem |
This aligns the library [with the Django documentation](https://docs.djangoproject.com/en/4.2/ref/models/querysets/#bulk-update) Also added support for validate_constraints in [full_clean](https://docs.djangoproject.com/en/dev/ref/models/instances/#django.db.models.Model.full_clean) Resolves typeddjango#166
(As per #160, I'm forking a dedicated issue for this.)
I'm using mypy 0.720 with django-stubs 1.1.0 (from PyPI today):
With
plugins = mypy_django_plugin.main
inmypy.ini
, mypy fails as follows:even though mypy_django_plugin loads just fine.
I've tried dropping
.main
from the mypy.ini and that gives:I've also tried replacing
.main
with:main
(which seems to be the current recommended way to specify entry points inmypy.ini
) and that gives:The text was updated successfully, but these errors were encountered: