Backend Import Errors
Backend Import Errors
Critical: GraphQL 500 Errors with CORS Failures
Symptoms
- GraphQL returns 500 errors
- CORS failures in browser console
- “Load failed” errors in frontend
- Backend completely unresponsive
Root Cause
Incorrect imports in the backend Python code cause the entire backend to fail during initialization.
Common Import Errors
# ❌ WRONG - These functions don't exist and crash the backend
from .db_postgres import create_async_engine # Function doesn't exist
from .db_neo4j import AsyncGraphDatabase # Function doesn't exist
# ✅ CORRECT - Use actual packages
from sqlalchemy.ext.asyncio import create_async_engine
from neo4j import AsyncGraphDatabase
How to Fix
- Check Recent Backend Changes
- Look for any new or modified Python files
- Search for import statements from
.db_postgresor.db_neo4j
- Correct the Imports
# PostgreSQL imports from sqlalchemy.ext.asyncio import create_async_engine from sqlalchemy import text # Neo4j imports from neo4j import AsyncGraphDatabase, GraphDatabase - Verify Backend Starts
cd Plings-Backend python -m uvicorn app.main:app --reload - Test GraphQL Endpoint
- Navigate to http://localhost:8000/graphql
- Should see GraphiQL interface
- Try simple query:
{ _health }
Prevention
- Always use package imports, not local module imports for database drivers
- Test backend startup after any import changes
- Keep imports at top of file and organized by type
Related Issues
This is the #1 cause of “Load failed” errors in the frontend. The backend crashes during initialization, so no endpoints are available, causing CORS errors as a secondary symptom.
See also: