Skip to content

api/data_io.py:242: from sqlalchemy import create_engine, text as sql_text ModuleNotFoundError: No module named 'sqlalchemy' → ValueError: SQL import requires sqlalchemy (pip install sqlalchemy) #17

Description

@ranasl62

Cause: api/data_io.py import_sql() depends on SQLAlchemy, but sqlalchemy is not listed in requirements.txt (CI installs pip install -r requirements.txt then -e .).

Also leaves uncovered: api/data_io.py lines 245–248 (engine connect / read_sql after successful import).

Failure 2 — coverage < 100%

File Miss Lines
api/data_io.py 4 245–248
api/jobs.py 4 485, 504–506
api/researcher_routes.py 7 112–113, 137, 154, 166–167, 742
openhealth/trust_pack.py 2 164, 166
TOTAL 17 99.38%

Likely branches: CSV header parse failure, reconcile early-returns, HPO temporal_splitsplit_by_patient=False, SHAP purge/remirror, trust_pack mirror skip for missing/invalid PNG.

Expected

  • CI green with cov-fail-under=100
  • Either SQLAlchemy is a declared CI/runtime dep, or the test mocks the ImportError path and separate tests cover the happy path when SQLAlchemy is present

Proposed fix

  • Add sqlalchemy to requirements.txt (or requirements-dev.txt + CI install) so import_sql works in CI
  • Ensure test_data_io_delete_symlink_and_imports exercises the success path (or split ImportError vs happy-path tests)
  • Add small unit tests / fixtures for remaining miss lines (jobs SHAP cleanup, trust_pack.mirror_to_shared early returns, researcher_routes header/reconcile/HPO temporal_split)
  • Re-run: PYTHONPATH=. pytest tests/ -m "not e2e" -q --tb=short → 0 fail, coverage ≥ 100%

Notes

  • Warnings (Starlette TestClient/httpx, shap colormap, pandas copy=) are noise for this issue; track separately if desired.
  • Local runs with --no-cov may hide the coverage gate; CI uses pytest.ini defaults.

Acceptance criteria

  • No ModuleNotFoundError: sqlalchemy in CI
  • test_data_io_delete_symlink_and_imports passes
  • Coverage total ≥ 100% for configured packages (api, openhealth)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions