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

ImportError: cannot import name 'Datasette' from partially initialized module 'datasette.app' #6

Closed
simonw opened this issue Apr 26, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@simonw
Copy link
Contributor

simonw commented Apr 26, 2024

Got this with datasette-test>=0.3 as a dependency. I'm going to yank that release.

@simonw simonw added the bug Something isn't working label Apr 26, 2024
@simonw
Copy link
Contributor Author

simonw commented Apr 26, 2024

CleanShot 2024-04-26 at 11 36 23@2x

@simonw
Copy link
Contributor Author

simonw commented Apr 26, 2024

I clearly introduced a circular import when I made this a plugin in #4.

@simonw
Copy link
Contributor Author

simonw commented Apr 26, 2024

Traceback:

datasette-secrets % pytest
======================================================================= test session starts =======================================================================
platform darwin -- Python 3.10.10, pytest-8.1.1, pluggy-1.5.0
rootdir: /Users/simon/Dropbox/Development/datasette-secrets
configfile: pyproject.toml
plugins: anyio-4.3.0, asyncio-0.23.6
asyncio: mode=strict
collected 0 items / 1 error                                                                                                                                       

============================================================================= ERRORS ==============================================================================
_____________________________________________________________ ERROR collecting tests/test_secrets.py ______________________________________________________________
ImportError while importing test module '/Users/simon/Dropbox/Development/datasette-secrets/tests/test_secrets.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/opt/homebrew/Caskroom/miniconda/base/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_secrets.py:4: in <module>
    from datasette.cli import cli
../datasette/datasette/cli.py:17: in <module>
    from .app import (
../datasette/datasette/app.py:40: in <module>
    from .views.database import database_download, DatabaseView, TableCreateView
../datasette/datasette/views/database.py:35: in <module>
    from datasette.plugins import pm
../datasette/datasette/plugins.py:64: in <module>
    pm.load_setuptools_entrypoints("datasette")
/opt/homebrew/Caskroom/miniconda/base/lib/python3.10/importlib/metadata/__init__.py:171: in load
    module = import_module(match.group('module'))
/opt/homebrew/Caskroom/miniconda/base/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
../../../.local/share/virtualenvs/datasette-secrets-rV3AX-Bq/lib/python3.10/site-packages/datasette_test/__init__.py:1: in <module>
    from datasette.app import Datasette as _Datasette
E   ImportError: cannot import name 'Datasette' from partially initialized module 'datasette.app' (most likely due to a circular import) (/Users/simon/Dropbox/Development/datasette/datasette/app.py)
===================================================================== short test summary info =====================================================================
ERROR tests/test_secrets.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
======================================================================== 1 error in 0.29s =========================================================================

@simonw
Copy link
Contributor Author

simonw commented Apr 26, 2024

I'm pretty sure what's happening is that even attempting to import datasette_test.plugins is triggering an import of that datasette_test/__init__.py module which tries to import from datasette.app before it's ready.

@simonw
Copy link
Contributor Author

simonw commented Apr 26, 2024

I'm going to split it off into a separate plugin package, and make that a dependency of datasette-test.

simonw added a commit to datasette/datasette-test-plugin that referenced this issue Apr 26, 2024
simonw added a commit that referenced this issue Apr 26, 2024
@simonw simonw closed this as completed Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant