I have encountered this bug while developing a helper script next to my docker-compose configuration for CKAN stack. Next to the script I have a ckan directory with a Dockerfile and image related stuff.
I'm not sure if it's a proper fix for this, but earlier behaviour depending on fallback on import ckan looked weak to me. I think we should generate error classes stubs only after actual classes we need fail to import.
Minimal steps to reproduce the issue:
create a script main.py with the following content:
# main.py
import ckanapi
if name == 'main':
print("Works.")
2. Running the script with `python3 main.py` works fine.
3. Create an empty directory ckan
mkdir ckan
project directory tree:
.
├── ckan # empty directory
└── main.py
4. Running the script errors with:
$ python3 main.py
Traceback (most recent call last):
File "main.py", line 1, in
import ckanapi
File "/home/tomek/tmp/venv/local/lib/python3.6/site-packages/ckanapi/init.py", line 8, in
from ckanapi.errors import (
File "/home/tomek/tmp/venv/local/lib/python3.6/site-packages/ckanapi/errors.py", line 63, in
from ckan.logic import (NotAuthorized, NotFound, ValidationError)
ModuleNotFoundError: No module named 'ckan.logic'
because python import the local directory ckan as a package and it causes the error stubs generation in `ckanapi.errors` to fail.
Overview
I have encountered this bug while developing a helper script next to my docker-compose configuration for CKAN stack. Next to the script I have a
ckan
directory with a Dockerfile and image related stuff. I'm not sure if it's a proper fix for this, but earlier behaviour depending on fallback onimport ckan
looked weak to me. I think we should generate error classes stubs only after actual classes we need fail to import.Minimal steps to reproduce the issue:
main.py
with the following content:if name == 'main': print("Works.")
mkdir ckan
. ├── ckan # empty directory └── main.py
$ python3 main.py Traceback (most recent call last): File "main.py", line 1, in
import ckanapi
File "/home/tomek/tmp/venv/local/lib/python3.6/site-packages/ckanapi/init.py", line 8, in
from ckanapi.errors import (
File "/home/tomek/tmp/venv/local/lib/python3.6/site-packages/ckanapi/errors.py", line 63, in
from ckan.logic import (NotAuthorized, NotFound, ValidationError)
ModuleNotFoundError: No module named 'ckan.logic'