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 in target file accidentally triggers 'No module named ... found' #2757

Closed
1 task done
Bluenix2 opened this issue Jun 2, 2023 · 0 comments · Fixed by #2770
Closed
1 task done

Circular import in target file accidentally triggers 'No module named ... found' #2757

Bluenix2 opened this issue Jun 2, 2023 · 0 comments · Fixed by #2770

Comments

@Bluenix2
Copy link
Contributor

Bluenix2 commented Jun 2, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

While developing it appears that I accidentally caused a circular import which Python traces back to starting in the file I have my app in. As a result, Python outputs an error such as the following:

ImportError: cannot import name 'constants' from partially initialized module 'app' (most likely due to a circular import) (/api/app/__init__.py)

In this case my module I pass to the sanic server is app:app, from within /api.

Code snippet

No response

Expected Behavior

I had this in the back of my mind the entire time, but found it very difficult to troubleshoot due to Sanic swallowing the error. As a result I ended up the rabbit hole of accidental breaking changes and tried commenting out different changes. An hour later I finally found the right import.

It would help if Sanic continued to output the specific import error, on the off-chance that it isn't an incorrectly setup module. The alternative would be to use more fine-grained importlib and manually call some functions rather than use their help functions. As a result there should be a different call which finds the file (an ImportError here hints at an incorrectly setup module), than the one which loads it (user error).

How do you run Sanic?

Sanic CLI

Operating System

Windows (Docker, Python:3.11)

Sanic Version

23.3

Additional context

No response

@Bluenix2 Bluenix2 added the bug label Jun 2, 2023
moshe742 added a commit to moshe742/sanic that referenced this issue Jul 5, 2023
ahopkins added a commit that referenced this issue Jul 5, 2023
…ced import error (#2770)

Co-authored-by: Adam Hopkins <adam@amhopkins.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants