Skip to content

Fix ModuleNotFoundError: update libs.* imports to src.libs.*#74

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-imports-from-libs
Draft

Fix ModuleNotFoundError: update libs.* imports to src.libs.*#74
Copilot wants to merge 3 commits intomainfrom
copilot/fix-imports-from-libs

Conversation

Copy link
Contributor

Copilot AI commented Mar 24, 2026

Python cannot resolve libs as a top-level package because the modules live under src/libs/, causing ModuleNotFoundError: No module named 'libs.data_protection'; 'libs' is not a package and failing test collection entirely.

Changes

  • Updated all from libs.<module> import ... statements to from src.libs.<module> import ... across all source and test files

Affected files: src/main.py, src/models.py, src/handlers/{auth,bugs,domains,organizations,stats,users}.py, tests/test_orm.py

# Before
from libs.data_protection import encrypt_sensitive, decrypt_sensitive, blind_index
from libs.db import get_db_safe
from libs.orm import Model

# After
from src.libs.data_protection import encrypt_sensitive, decrypt_sensitive, blind_index
from src.libs.db import get_db_safe
from src.libs.orm import Model
Original prompt

The codebase fails tests due to errors like:

ModuleNotFoundError: No module named 'libs.data_protection'; 'libs' is not a package

This occurs because Python cannot locate 'libs' as a top-level package—it's under 'src/libs/'.

Solution:

  • Change all imports like from libs.data_protection import ... to from src.libs.data_protection import ... (and similarly for all imports from 'libs').
  • Do the same adjustment for other 'libs' imports like 'libs.orm', 'libs.constant', and 'libs.db'.

Alternatively, adding 'src' to PYTHONPATH can work, but changing the imports is the most direct and least surprising fix and matches the project layout.

Scope:

  • Apply these changes across all relevant Python source and test files.
  • Ensure all previously failing tests now import from 'src.libs.*' and pass collection phase.

Example fix:

# Before:
from libs.data_protection import ...

# After:
from src.libs.data_protection import ...

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Please find a solution for this failing job. Use the logs, job definition, and any referenced files where the failure occurred. Keep your response focused on the solution and include code suggestions when appropriate.

Assistant: The job is failing because of import errors such as:

ModuleNotFoundError: No module named 'libs.data_protection'; 'libs' is not a package

This is due to import statements like:

from libs.data_protection import encrypt_sensitive, decrypt_sensitive, blind_index

in your code (e.g., src/handlers/users.py).

However, the actual file is located at src/libs/data_protection.py, not libs/data_protection.py. Python will not find the package unless imports use the correct relative or absolute path based on your directory structure.

Solution:

Update all imports of libs.* in your codebase to src.libs.*, or fix your Python module search path (PYTHONPATH). The quickest fix is to change imports like this:

Before:

from libs.data_protection import encrypt_sensitive, decrypt_sensitive, blind_index

After:

from src.libs.data_protection import encrypt_sensitive, decrypt_sensitive, blind_index

Apply the same pattern for all other libs.* imports, e.g., use from src.libs.orm import ... when importing from libs/orm.py.

Alternatively, add src/ to your PYTHONPATH in your test setup:

env:
  PYTHONPATH: src/

in your .github/workflows/tests.yml file, before running your Python tests.

Summary of changes to make:

  • Fix all import paths to match your source file structure (src/libs/...).
  • Or, add src/ to your PYTHONPATH.

This will resolve the ModuleNotFoundError and allow your tests to run.

User: Create a pr to fix it

Assistant: I'm waiting for your response to proceed with creating the pull request to fix the import errors.

This pull request was created from Copilot chat.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 24, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
❌ Deployment failed
View logs
blt-api d4ed6fb Mar 24 2026, 03:38 AM

Copilot AI changed the title [WIP] Fix imports from libs to src.libs in all files Fix ModuleNotFoundError: update libs.* imports to src.libs.* Mar 24, 2026
Copilot AI requested a review from DonnieBLT March 24, 2026 03:28
@DonnieBLT
Copy link
Contributor

@copilot tests are failing

…ata/.status attributes

Co-authored-by: DonnieBLT <128622481+DonnieBLT@users.noreply.github.com>
Agent-Logs-Url: https://github.com/OWASP-BLT/BLT-API/sessions/7e6c5eb5-fac7-4f66-bff6-bb3043219694
Copy link
Contributor Author

Copilot AI commented Mar 24, 2026

@copilot tests are failing

Fixed in d4ed6fb. The 14 failures were caused by two mismatches between test expectations and the Response shims:

  1. conftest.py's Response.json() and Response.new() returned plain dicts, but tests accessed .data and .status as attributes — fixed by returning _WorkersResponse objects with those attributes.
  2. utils.py's MockResponse lacked a .data attribute needed by the auth tests — fixed by parsing .data from the JSON body.

All 195 tests now pass.

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

Successfully merging this pull request may close these issues.

2 participants