13.2 Commands, checks, and testing
The system check framework and --deploy guards
How does CheckRegistry collect checks from models, fields, settings, and third-party apps, and which security mistakes are caught only when --deploy is passed?
Before Django runs migrations, starts "runserver", or executes your test suite, it runs a fast static verification pass across every model, field, URLconf, template backend, cache config, and installed app. That verification engine lives in django/ — centered on one singleton CheckRegistry.
Two registries inside CheckRegistry — and why Tags.database is opt-in
Open CheckRegistry and CheckRegistry:
self.registered_checks = set()
self.deployment_checks = set()
Every subsystem in Django (models, fields, admin, auth, security, templates, tasks, staticfiles, URLs) registers check functions tagged with constants from Tags — such as Tags.models, Tags.admin, Tags.security, and Tags.database — returning lists of CheckMessage subclasses (Debug 10, Info 20, Warning 30, Error 40, Critical 50). Anything at or above "fail_level" (Error 40 by default) aborts command startup with SystemCheckError unless explicitly listed in "settings.
Look closely at two checks that ordinary "manage intentionally skips:
- Deployment checks (
deploy=True): Functions registered via"@register(Tagslive exclusively in.security, deploy=True)" CheckRegistry(.deployment_checks 21checks in Django6.1.3!) — completely separate from the30always-on static checks in"self. During normal development,.registered_checks" run_checks(include_deployment_checks=False)never calls them, because local development servers run over plain HTTP withDEBUG=Trueand would drown in false alarms! You ONLY execute them when you run"python manage(ideally inside CI/CD against your production settings module!)..py check --deploy" - Database checks (
Tags.database): Look at lines 90–94 ofdjango/: ifcore/ checks/ registry .py "tags"isNoneAND"databases"is not explicitly passed,CheckRegistryfilters out every.run_checks Tags.databasecheck so static checks never open a live database connection! Passing"--database default"(or running"manage.py test", whereDiscoverRunnerpasses active test aliases) turns them on..run_checks
Running check vs. check --deploy on the desk project
Watch "desk/" (which has DEBUG = False, ALLOWED_HOSTS populated, and all security middleware installed, yet lacks production HTTPS headers and secure cookie flags) pass normal check with 0 issues while check --deploy immediately flags four production security warnings (level=30):
2. CheckRegistry static checks vs --deploy checks on desk/
registry_counts: registered=30 deployment=21 tags=14
desk_check: static_issues=0 deploy_issues=4 deploy_ids=['security.W004(30)', 'security.W008(30)', 'security.W012(30)', 'security.W016(30)']
Look at those four exact deployment warnings caught only by "--deploy":
"security.W004":"SECURE_HSTS_SECONDS"is unset (browsers will not enforce HTTP Strict Transport Security)."security.W008":"SECURE_SSL_REDIRECT"isFalse(plain HTTP requests are not redirected to HTTPS)."security.W012":"SESSION_COOKIE_SECURE"isFalse(session cookies could traverse an unencrypted HTTP link)."security.W016":"CSRF_COOKIE_SECURE"isFalse(CSRF cookies could traverse plain HTTP).
Adding "python manage against your production settings in CI ensures none of those four production omissions ever slips past local green builds.
Running "manage invokes these checks too — inside a surprisingly subtle two-process architecture that makes AppConfig.ready execute twice. We dissect the autoreloader next in Why runserver runs two processes.