Troubleshooting API Generation
Common issues and solutions when generating API clients with Django-CFG API Client Generation.
TypeScript Generation Issues
gen fails with tsc diagnostics
Problem: a TypeScript target fails with error TS… lines, and the app keeps its previous tree.
That is the type-check gate: the new tree did not compile for your app. Do not patch the generated file; the fix belongs in the serializer or view, the Target options, or the runtime.
TS2353(an unknown property in an object literal) onauth,originorskipAuthRefresh: the installed@djangocfg/apiis older than the generator. Upgrade both together (make update).- An import from
@djangocfg/apithat does not resolve in a fresh checkout: the runtime’sdisttypes are not built yet. Build it, or run once withDJANGO_CFG_GEN_SKIP_TYPECHECK=1. - Anything else: generate with
DJANGO_CFG_GEN_SKIP_TYPECHECK=1, then run your app’stsc --noEmitto read the error in place.
Validate the schema and the targets first:
python manage.py spectacular --validate
python manage.py gen --list-targets
DJANGO_CFG_GEN_NO_CACHE=1 python manage.py gengen names a view and stops
An operationId collision, an operation without a response schema, an unknown group, an unknown x-cfg-auth value,
a direct_origin_tags entry no operation carries, or an @invalidated_by topic whose parameter is no path
parameter of the GET. Each message names the route, the view and the fix.
Browser Request Issues (TypeScript)
Requests go to the page’s own origin (404 on /cfg/... or /apix/...)
The browser resolved a relative URL. Check, in this order: the value BaseApp gets as auth.apiUrl,
NEXT_PUBLIC_STATIC_BUILD, NEXT_PUBLIC_API_PROXY_URL (an empty value means same-origin on purpose), then
NEXT_PUBLIC_API_URL. The full order is in API origin modes. If your own code reads
the variable, it must read the literal process.env.NEXT_PUBLIC_API_URL; see Pitfalls.
APIConfigurationError: API origin is not configured
Nothing resolved for this request. On the server, only NEXT_PUBLIC_API_URL or an explicit absolute origin count:
a proxy or static build does not apply there. Set NEXT_PUBLIC_API_URL for server rendering.
Data in the wrong language after a locale switch
The query key holds no locale. Invalidate after the switch; see Pitfalls.
A realtime list does not refresh
The view needs @invalidated_by("topic"), the tree must be regenerated, and the hook must run in BaseApp’s
QueryClient (no client passed to the hook, no second provider). See
Realtime: frontend.
Schema Generation Issues
ModuleNotFoundError: No module named ‘django_cfg’
Problem:
Schema generation fails with import errors when running manage.py gen.
Root Cause:
Django-CFG API Client Generation spawns subprocess calls to manage.py spectacular using the wrong Python interpreter (system Python instead of virtualenv Python).
Solution:
Fixed in Django-CFG Client Generator v1.4+ by using sys.executable instead of hardcoded "python" in subprocess calls.
If using older version, ensure you’re running commands with the virtualenv Python:
.venv/bin/python manage.py genOrval reports a schema or operation error
Problem:
Orval consumes the staged OpenAPI slice and fails when references, operation IDs, tags, or generated Zod/runtime types are ambiguous.
Root Cause:
The source of truth is the Django schema, not a generated TypeScript file.
Solution:
Check the generated OpenAPI JSON for missing $ref targets, duplicate enum
names, missing tags, and unstable operation IDs. Fix the serializer or
@extend_schema declaration, then regenerate.
Python Client Generation Issues
openapi-python-client not found
Problem:
Python client generation fails with command not found.
Solution:
Install openapi-python-client:
pip install openapi-python-clientOr add to your project dependencies:
[tool.poetry.dependencies]
openapi-python-client = "^0.15.0"Browser Request Issues (CORS)
CORS error, but the server sees only OPTIONS
A generated client sends a custom header that the preflight did not allow; the browser blocks the real request, so the server log shows OPTIONS 200 and no PUT/POST. curl works because it sends no preflight.
Preflights from an already-trusted origin are answered with the headers they ask for, so this normally means the origin is not trusted or cors_reflect_request_headers = False is set. See Reading an opaque CORS error.
General Tips
Enable debug logging
Add to your Django settings:
LOGGING = {
'loggers': {
'django_cfg.client': {
'level': 'DEBUG',
},
},
}Check generated schemas
Each group’s schema is served at /cfg/openapi/{group}/schema/ (with Swagger UI
at /cfg/openapi/{group}/docs/ and ReDoc at
/cfg/openapi/{group}/redoc/), and the OpenAPI spec is saved as openapi.json
next to a TypeScript target’s output. Inspect it to verify:
- All required components exist
- References are correct
- No duplicate definitions
Regenerate from scratch
If you encounter persistent issues:
# Skip the cache and regenerate
DJANGO_CFG_GEN_NO_CACHE=1 python manage.py genType-check the app
The gate checks the generated tree. Your own code against it is checked by your app:
pnpm exec tsc --noEmitGetting Help
If you encounter issues not covered here:
- Check the Django-CFG API client generation output in the container/terminal logs (stdout), or under
logging.dirif you set one - Review the generated OpenAPI schemas
- Report issues at django-cfg issues