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

Circular import when running example #92

Closed
yaseralnajjar opened this issue Dec 13, 2020 · 4 comments
Closed

Circular import when running example #92

yaseralnajjar opened this issue Dec 13, 2020 · 4 comments

Comments

@yaseralnajjar
Copy link
Contributor

yaseralnajjar commented Dec 13, 2020

After installing dependencies, I run the following command:

poetry run python example/manage.py runserver 0:8000

And circular import issue occurred:

λ poetry run python example/manage.py runserver 0:8000
Watching for file changes with StatReloader
Performing system checks...

Exception in thread django-main-thread:
Traceback (most recent call last):
  File "C:\Users\kasse\AppData\Local\pypoetry\Cache\virtualenvs\django-unicorn-Lz1J1cta-py3.9\lib\site-packages\django\template\utils.py", line 66, in __getitem__
    return self._engines[alias]
KeyError: 'django'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\kasse\AppData\Local\pypoetry\Cache\virtualenvs\django-unicorn-Lz1J1cta-py3.9\lib\site-packages\django\template\backends\django.py", line 121, in get_package_libraries
    module = import_module(entry[1])
  File "c:\users\kasse\appdata\local\programs\python\python39\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "C:\Users\kasse\Desktop\django-unicorn\django_unicorn\templatetags\unicorn.py", line 8, in <module>
    from ..components import UnicornView
ImportError: cannot import name 'UnicornView' from partially initialized module 'django_unicorn.components' (most likely due to a circular import) (C:\Users\kasse\Desktop\django-unicorn\django_unicorn\components.py)

Suggested fix:

Move the import before the usage of UnicornView

        from ..components import UnicornView
        view = UnicornView.create(
            component_id=component_id,
            component_name=self.component_name,
            kwargs=resolved_kwargs,
            request=request,
        )
        rendered_component = view.render(init_js=True)

Is it the appropriate fix?

@adamghill
Copy link
Owner

adamghill commented Dec 13, 2020

Hmm, well I've never seen this happen before! Moving the seems like a fine fix, but I wish I could reproduce the error on my local.

If you move the import does it import correctly?

Also: any chance you can run poetry debug and poetry show and paste the output in here?

@yaseralnajjar
Copy link
Contributor Author

Yeah, after moving it works just fine.

I used latest Python and Django (maybe this will help you to reproduce the issue).

@adamghill
Copy link
Owner

Ok, awesome! If you want to make a PR I'll merge it right away. Or I can make the change and credit you with the fix.

@yaseralnajjar
Copy link
Contributor Author

Created the PR... Didn't know how to avoid including the previous commit there 😕

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

2 participants