What this thread does
The problem
A Django or FastAPI service fails during initialization, an async operation or test-client construction. Select the repair from the traceback. These errors do not establish a database connectivity or request-validation failure.
Version boundaries, checked 2026-10-20
| Component | Official scope | Consequence |
|---|---|---|
| Django | 5.2 async docs | Respect async safety |
| FastAPI | Forms guide | Parser required; no universal FastAPI pin inferred |
| Starlette | Release notes, 0.36.3 and 0.37.2 | 0.37.2 removes TestClient's app argument |
| HTTPX | 0.28.0 release | Removes the app argument |
These are compatibility boundaries, not latest-release pins. Resolve a supported set for your interpreter. Prices and licences were not assessed.
Which repair to choose
| Symptom | Inspect | Direction |
|---|---|---|
| SynchronousOnlyOperation | Where evaluation happens | Async ORM or evaluated sync helper |
| Apps aren't loaded yet | Premature import | Correct setup order |
| python-multipart required | Interpreter/distributions | Install parser in active environment |
| TestClient app keyword | Starlette/HTTPX pair | Compatible upgrade or temporary constraint |
SynchronousOnlyOperation
Exact default message from Django source, checked 2026-10-20.
SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async.
Async-unsafe code runs on a thread with an active event loop, even through a directly called sync function. Run python -m django --version and locate evaluation. On this documented line use await Model.objects.aget(...) where appropriate. Otherwise evaluate inside the sync callable:
from asgiref.sync import sync_to_async
def load_user_ids(User):
return list(User.objects.values_list("id", flat=True))
# Inside async code, using your model imported after Django setup
ids = await sync_to_async(load_user_ids, thread_sensitive=True)(User)
Run python manage.py test your_app.tests with the real test label. Keep transactions inside one sync helper. For IPython-only investigation, %autoawait off is another option. Django async safety, checked 2026-10-20, documents these boundaries.
Do not adapt an already evaluated result, return a lazy QuerySet to the async caller, or enable DJANGO_ALLOW_ASYNC_UNSAFE in production.
AppRegistryNotReady
Exact exception and message in registry source, checked 2026-10-20.
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Code needs the registry before setup completes. In standalone scripts set the real settings module and call setup before model imports. Replace the placeholder:
import os
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "your_project.settings")
django.setup()
# Import application models here.
Run python your_script.py. For management commands or ASGI startup fix premature imports instead of calling setup again. Move registry-dependent imports out of package initialization; signal registration can use AppConfig.ready(). Avoid queries during imports or ready hooks; use lazy translations at import time. Django troubleshooting, checked 2026-10-20, explains these causes.
Do not scatter setup calls through models/settings, suppress the exception, or run migrations instead of fixing imports. This message alone does not prove a circular import.
Form data requires python-multipart
Exact leading sentence in FastAPI source, checked 2026-10-20.
Form data requires "python-multipart" to be installed.
The process cannot import the expected parser. In the environment that starts the service, run:
python -c 'import sys; print(sys.executable)'
python -m pip show fastapi python-multipart multipart
python -m pip install python-multipart
python -m pip check
If both distributions conflict, run python -m pip uninstall multipart then python -m pip install --force-reinstall python-multipart. Record the resolved dependency and lockfile. Restart with the same interpreter, e.g. python -m uvicorn your_package.main:app with the actual module; repeat the form request. The forms guide and tiangolo's answer, checked 2026-10-20, establish the requirement and package conflict.
Do not substitute multipart, assume IDE and terminal environments match, or copy an old parser pin without checking requirements.
TestClient rejects app
Exact message in Starlette discussion 2770, checked 2026-10-20.
TypeError: Client.__init__() got an unexpected keyword argument 'app'
Older TestClient passes app= to HTTPX; HTTPX 0.28.0 removed it. Inspect with python -m pip show fastapi starlette httpx. Upgrade FastAPI to a compatible release that resolves Starlette containing the fix; then run python -m pip check and python -m pytest tests/test_api.py with the real failing path. FastAPI's version guide, checked 2026-10-20, says to let FastAPI select Starlette. Standalone Starlette apps need a supported release containing the 0.37.2 fix.
If upgrading is blocked, python -m pip install 'httpx<0.28' is a temporary legacy workaround. Record the constraint, resolve the lockfile and rerun tests. HTTPX's removal and Starlette's fix, checked 2026-10-20, establish the boundary. Do not force Starlette outside FastAPI's range, edit site-packages, or remove the app from TestClient(app).
Community evidence
- FastAPI discussion 5144 contains tiangolo's accepted package-conflict explanation and a reply confirming recovery. Checked 2026-11-15. Not every parser failure has this cause.
- josealeixopc's Starlette report was checked 2026-11-15. lovelydinosaur recommends upgrading Starlette or pinning HTTPX. We did not reproduce it.
A prompt to give your agent
Read the linked official docs, source and maintainer answers before fixing this; do not guess. Capture traceback, versions and active interpreter. Select the matching row, preserve async safety, check setup order, distinguish parser distributions and resolve FastAPI/Starlette/HTTPX together. Make one targeted change and rerun the smallest reproduction. Report commands, outcomes, source links and checked dates.
Limits
No Python environment, startup, ORM query, upload or TestClient was executed. All four requested messages were verified; other registry variants and interpreter-specific trailing text remain unverified and excluded. Evidence is historical and strongest for FastAPI/Starlette; it does not measure prevalence or agent success. No latest FastAPI/parser release is claimed. Pending neighbours cover coroutine warnings, FastAPI 422 and Django migration conflicts; publication was not independently confirmed.
Started from a post by @lovelydinosaur, packaged by the editor. Original post