2 months ago
Hi Railway Team,
I'm experiencing a persistent caching issue with my Django project.
Problem:
- I updated settings.py to add allauth.account.middleware.AccountMiddleware
- The file is correctly in GitHub (commit 77c678f)
- Railway builds successfully and installs all packages
- BUT: The app crashes with "AccountMiddleware must be added to settings.MIDDLEWARE"
- This suggests Railway is using an old cached version of settings.py
What I tried:
- Multiple git pushes with force
- Added comment to requirements.txt to force rebuild
- Verified settings.py is correct in repo
- All packages install correctly (django-allauth==0.57.0)
Question:
How can I clear the build cache or force Railway to use the new settings.py?
Thanks!
14 Replies
2 months ago
Hey there! We've found the following might help you get unblocked faster:
🧵 My service keeps crashing right after deployment with this error:
🧵 Railway deployment is not updating to the latest commit on the main branch.
If you find the answer from one of these, please let us know by solving the thread!
2 months ago
Railway is persistently caching an old version of
planmycamper/settings.py and refuses to load the updated version, despite multiple git pushes, file changes, and even file renaming attempts. This makes it impossible to deploy configuration changes.
Initial Issue:
After adding django-cookie-consent package and its middleware to
settings.py, the deployment started failing with:
django.core.exceptions.ImproperlyConfigured: allauth.account.middleware.AccountMiddleware must be added to settings.MIDDLEWAREHowever, the middleware IS present in settings.py (line 123):
MIDDLEWARE = [
...
"allauth.account.middleware.AccountMiddleware",
...
]What We Tried (All Failed):
Attempt 1: Remove problematic package
Removed
django-cookie-consentfromINSTALLED_APPSandrequirements.txt
Removed its middleware from
MIDDLEWAREGit pushed changes
Result: Railway still showed the OLD error about missing AccountMiddleware
Attempt 2: Force cache clear with comment changes
Changed comments in
settings.py to force Railway to recognize file changes
Added timestamps to comments (e.g., "Updated 2025-09-30 20:15")
Result: Railway still loaded old cached version
Attempt 3: Dummy commits
Created empty commits with
git commit --allow-emptyResult: No effect, same cached file loaded
Attempt 4: Environment variable
Set
NIXPACKS_NO_CACHE="1"in Railway environment variablesResult: Build cache cleared, but
settings.py still cached at runtime
Attempt 5: Rename settings file
Created backup branch:
backup-before-renameRenamed
settings.py to
settings_new.pyUpdated all references in
manage.py,
wsgi.py,
asgi.py
Git pushed changes
Result: Railway loaded an EMPTY or CORRUPTED settings file, showing errors about missing basic middleware that IS present in the file:
?: (admin.E408) 'django.contrib.auth.middleware.AuthenticationMiddleware' must be in MIDDLEWARE
?: (admin.E409) 'django.contrib.messages.middleware.MessageMiddleware' must be in MIDDLEWARE
?: (admin.E410) 'django.contrib.sessions.middleware.SessionMiddleware' must be in MIDDLEWAREEvidence of Caching Bug:
Local environment:
Server runs perfectly with python manage.py runserver
All middleware present and working
No configuration errors
Railway environment:
Consistently shows errors about missing middleware that EXISTS in the file
Even after renaming the file, Railway loads wrong/old content
Build logs show correct package installation, but deploy fails with middleware errors
Git commits showing all changes were pushed:
Multiple commits removing cookie-consent package
Multiple commits updating middleware configuration
Final commit renaming settings.py to settings_new.py
Current State:
Framework: Django 5.0.7
Python: 3.12
Region: europe-west4
Status: All deployments crashing with middleware errors
Public Repo: GitHub (can provide link if needed)
Expected Behavior:
Railway should load the current version of
settings.py from the git repository on each deployment.
Actual Behavior:
Railway persistently loads a cached/old version of
settings.py, ignoring all git pushes and file changes. Even renaming the file results in Railway loading corrupted/empty settings.
Requested Action:
Clear ALL file-level caches for this project
Force reload of Python settings files from latest git commit
Investigate why file-level caching is persisting across deployments and surviving file renames
Temporary Workaround Attempted:
We tried downgrading django-allauth from 0.57.0 to 0.52.0 (which doesn't require AccountMiddleware), but Railway still shows errors about missing basic Django middleware (SessionMiddleware, AuthenticationMiddleware, MessageMiddleware) that ARE clearly present in the current settings file.
Impact:
CRITICAL - Production site is down. Unable to deploy any configuration changes due to persistent file caching.
Additional Context:
This appears to be a file-level cache that persists beyond normal build caches
The cache survives
NIXPACKS_NO_CACHE=1The cache even survives renaming the file
Local development works perfectly with the same code
We suspect Railway is caching Python module imports or the settings file at a deeper level than the normal build cache.
Please help clear the persistent cache so we can deploy the correct settings file. Happy to provide any additional information needed.
tjayfl
Railway is persistently caching an old version ofplanmycamper/settings.py and refuses to load the updated version, despite multiple git pushes, file changes, and even file renaming attempts. This makes it impossible to deploy configuration changes.Initial Issue:After adding django-cookie-consent package and its middleware tosettings.py, the deployment started failing with:django.core.exceptions.ImproperlyConfigured: allauth.account.middleware.AccountMiddleware must be added to settings.MIDDLEWAREHowever, the middleware IS present in settings.py (line 123):pythonMIDDLEWARE = [ ... "allauth.account.middleware.AccountMiddleware", ... ]What We Tried (All Failed):Attempt 1: Remove problematic packageRemoved django-cookie-consent from INSTALLED_APPS andrequirements.txtRemoved its middleware from MIDDLEWAREGit pushed changesResult: Railway still showed the OLD error about missing AccountMiddlewareAttempt 2: Force cache clear with comment changesChanged comments insettings.py to force Railway to recognize file changesAdded timestamps to comments (e.g., "Updated 2025-09-30 20:15")Result: Railway still loaded old cached versionAttempt 3: Dummy commitsCreated empty commits with git commit --allow-emptyResult: No effect, same cached file loadedAttempt 4: Environment variableSet NIXPACKS_NO_CACHE="1" in Railway environment variablesResult: Build cache cleared, butsettings.py still cached at runtimeAttempt 5: Rename settings fileCreated backup branch: backup-before-renameRenamedsettings.py to settings_new.pyUpdated all references inmanage.py,wsgi.py,asgi.pyGit pushed changesResult: Railway loaded an EMPTY or CORRUPTED settings file, showing errors about missing basic middleware that IS present in the file:?: (admin.E408) 'django.contrib.auth.middleware.AuthenticationMiddleware' must be in MIDDLEWARE ?: (admin.E409) 'django.contrib.messages.middleware.MessageMiddleware' must be in MIDDLEWARE ?: (admin.E410) 'django.contrib.sessions.middleware.SessionMiddleware' must be in MIDDLEWAREEvidence of Caching Bug:Local environment:Server runs perfectly with python manage.py runserverAll middleware present and workingNo configuration errorsRailway environment:Consistently shows errors about missing middleware that EXISTS in the fileEven after renaming the file, Railway loads wrong/old contentBuild logs show correct package installation, but deploy fails with middleware errorsGit commits showing all changes were pushed:Multiple commits removing cookie-consent packageMultiple commits updating middleware configurationFinal commit renaming settings.py to settings_new.pyCurrent State:Framework: Django 5.0.7Python: 3.12Region: europe-west4Status: All deployments crashing with middleware errorsPublic Repo: GitHub (can provide link if needed)Expected Behavior:Railway should load the current version ofsettings.py from the git repository on each deployment.Actual Behavior:Railway persistently loads a cached/old version ofsettings.py, ignoring all git pushes and file changes. Even renaming the file results in Railway loading corrupted/empty settings.Requested Action:Clear ALL file-level caches for this projectForce reload of Python settings files from latest git commitInvestigate why file-level caching is persisting across deployments and surviving file renamesTemporary Workaround Attempted:We tried downgrading django-allauth from 0.57.0 to 0.52.0 (which doesn't require AccountMiddleware), but Railway still shows errors about missing basic Django middleware (SessionMiddleware, AuthenticationMiddleware, MessageMiddleware) that ARE clearly present in the current settings file.Impact:CRITICAL - Production site is down. Unable to deploy any configuration changes due to persistent file caching.Additional Context:This appears to be a file-level cache that persists beyond normal build cachesThe cache survives NIXPACKS_NO_CACHE=1The cache even survives renaming the fileLocal development works perfectly with the same codeWe suspect Railway is caching Python module imports or the settings file at a deeper level than the normal build cache.Please help clear the persistent cache so we can deploy the correct settings file. Happy to provide any additional information needed.
2 months ago
Hey, have you tried using Railpack instead of t Nixpacks (this can be changes within your service's Build section)? Alternatively, you can also try writing your own Dockerfile, which will give you full control over how your application is being built.
uxuz
Hey, have you tried using Railpack instead of t Nixpacks (this can be changes within your service's Build section)? Alternatively, you can also try writing your own Dockerfile, which will give you full control over how your application is being built.
2 months ago
Hi @uxuz,
Thank you for the suggestions! I've implemented both approaches, but unfortunately the caching issue has evolved.
Implemented: Railpack
Changed
railway.json to use Railpack as suggested:
{
"build": {
"builder": "RAILPACK"
}
}Result: Build succeeded, but the same configuration errors persisted in deployment.
Implemented: Custom Dockerfile
Created a custom Dockerfile with full control over the build process:
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
COPY docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]Updated
railway.json:
{
"build": {
"builder": "DOCKERFILE",
"dockerfilePath": "Dockerfile"
}
}Current Observation:
The build logs show successful completion:
✅ Using Detected Dockerfile
✅ Build time: 13.94 seconds
✅ Build successfulHowever, the deployment logs show:
Error: '$PORT' is not a valid port number.This error suggests the deployment is using a different configuration than what was just built.
Additional Steps Taken:
Added cache-breaking environment variables to Dockerfile
Modified Dockerfile structure to force rebuild
Verified all changes are committed and pushed to GitHub
Multiple deployment attempts with fresh commits
GitHub commits: 867486b → 7e4618b (showing progression of Dockerfile implementations)
Question:
Is there a recommended way to ensure Railway uses the freshly built Docker image for deployment? The build succeeds but the deployment appears to reference an earlier configuration.
Current Status:
Dockerfile builds successfully
All dependencies install correctly
Deployment references older configuration
Any guidance on ensuring the deployment uses the current build would be greatly appreciated.
Service:planmycamper.de (europe-west4)
Plan: PRO
Thank you for your help!
2 months ago
Interesting, in conclusion, Nixpacks, Railpack and Dockerfile seems to reference an earlier commit, this shouldn't be the case. Are you sure that you have connected to the correct GitHub branch within your service's settings? Additionally, would you be able to provide the repository or a minimal reproducible example for debugging purposes?
uxuz
Interesting, in conclusion, Nixpacks, Railpack and Dockerfile seems to reference an earlier commit, this shouldn't be the case. Are you sure that you have connected to the correct GitHub branch within your service's settings? Additionally, would you be able to provide the repository or a minimal reproducible example for debugging purposes?
2 months ago
Hi @uxuz,
thanks for looking into this! I've double-checked everything, here’s the full picture:
GitHub Setup 
Branch:
mainLatest Commit:
afb2058— "SIMPLIFY: Remove debug commands, add check --deploy and gunicorn timeout"Commit Time: Just now
settings.py Verification
The current code on GitHub is correct and includes the expected config:
MIDDLEWARE (lines 113–127):
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"planmycamper.middleware.www_redirect.WWWRedirectMiddleware",
"debug_toolbar.middleware.DebugToolbarMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"allauth.account.middleware.AccountMiddleware",
"planmycamper.middleware.feature_flags.FeatureFlagMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"django_htmx.middleware.HtmxMiddleware",
]
TEMPLATES (lines 132–146):
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [BASE_DIR / "templates"],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]
The Issue
Deployment logs throw:
(admin.E408) 'django.contrib.auth.middleware.AuthenticationMiddleware' must be in MIDDLEWARE
(admin.E409) 'django.contrib.messages.middleware.MessageMiddleware' must be in MIDDLEWARE
(admin.E410) 'django.contrib.sessions.middleware.SessionMiddleware' must be in MIDDLEWARE
(admin.E403) A 'django.template.backends.django.DjangoTemplates' instance must be configured in TEMPLATES
But these are clearly present in the code.
Evidence of Disconnect
Local env works fine with this commit
GitHub shows correct settings.py
Railway acts as if settings.pyis empty or outdated
Latest deployment with python manage.py check --deploy confirms: Railway is loading an empty settings.py (no middleware, no templates).
Likely Causes
Build/deploy cache not cleared
Old
.pycor persisted volume files being usedWrong branch or commit not being pulled
Request
Could you please:
Verify Railway is deploying from
mainat commitafb2058Clear all caches for this service (build + runtime + volume persistence)
Force a fresh deploy from GitHub
If that fails, consider deleting/recreating the service to break cache links
Context
Issue started after commit
7d1c556(added then removeddjango-cookie-consent)Errors persist across Nixpacks, Railpack, and Dockerfile builds
Strongly suggests this is a Railway platform caching problem, not app code
Repo is public if you need to check directly:
Thanks a lot for your support!
2 months ago
Hey, your repository is private, would it be possible to change it to public?
uxuz
Hey, your repository is private, would it be possible to change it to public?
2 months ago
Hi @uxuz,
I understand you need to see the code. However, my repository contains proprietary business logic.
Instead, here’s a minimal reproduction that demonstrates the exact issue:
The Problem
Railway is caching an old/corrupted version of planmycamper/settings.py and refuses to load the updated version from GitHub.
Proof
Current GitHub code (commit afb2058):
# planmycamper/settings.py - Lines 113-127
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"planmycamper.middleware.www_redirect.WWWRedirectMiddleware",
"debug_toolbar.middleware.DebugToolbarMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"allauth.account.middleware.AccountMiddleware",
"planmycamper.middleware.feature_flags.FeatureFlagMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"django_htmx.middleware.HtmxMiddleware",
]
Railway deployment error:
?: (admin.E408) 'django.contrib.auth.middleware.AuthenticationMiddleware' must be in MIDDLEWARE
?: (admin.E409) 'django.contrib.messages.middleware.MessageMiddleware' must be in MIDDLEWARE
?: (admin.E410) 'django.contrib.sessions.middleware.SessionMiddleware' must be in MIDDLEWARE
?: (admin.E403) A 'django.template.backends.django.DjangoTemplates' instance must be configured in TEMPLATES
This proves Railway is loading an empty/corrupted settings.py, not the GitHub code above.
What I’ve Tried
Multiple git pushes
Changed builder (Nixpacks → Railpack → Dockerfile)
Set NIXPACKS_NO_CACHE=1
Renamed settings.py→settings_new.py
Added cache-clearing commands to startCommand
Verified correct branch (main)
None of these resolved the issue. Railway still loads the outdated file.
Current Config (from GitHub)
MIDDLEWARE:
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"planmycamper.middleware.www_redirect.WWWRedirectMiddleware",
"debug_toolbar.middleware.DebugToolbarMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"allauth.account.middleware.AccountMiddleware",
"planmycamper.middleware.feature_flags.FeatureFlagMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"django_htmx.middleware.HtmxMiddleware",
]
TEMPLATES:
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [BASE_DIR / "templates"],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]
Both are present in my GitHub repo but Railway reports them as missing.
Request
Could you please verify on your side:
Is Railway definitely pulling from the latest GitHub commit?
Is there a deployment cache or volume-level cache preventing updates?
Could you manually clear all caches for this service?
Service Details
Service: planmycamper.de
Region: europe-west4
Plan: PRO
Last working deployment: Commit
7d1c556(rolled back)Failing deployments: All commits after
7d1c556
Thanks a lot for looking into this. Let me know if you need any additional logs.
2 months ago
Have you tried specifically pushing settings.py file to git? (git add settings.py; git commit -m "bla bla"; git push)
Have you tried specifically pushing settings.py file to git? (git add settings.py; git commit -m "bla bla"; git push)
2 months ago
@Anonymous - Yes, I've tried explicitly pushing settings.py:
git add planmycamper/settings.py
git commit -m "Explicit push: settings.py"
git push
Result: Railway STILL loads an empty/corrupted settings.py.
The file is correctly in GitHub (verified with git show),
but Railway reports ALL middleware as missing.
This confirms it's a Railway volume/cache persistence bug,
not a Git issue.
2 months ago
## UPDATE: Cross-Platform Testing Confirms Railway Platform Bug
I've conducted cross-platform testing to definitively isolate the issue:
### Test Setup
- Same codebase (commit 13ab600)
- Same requirements.txt
- Same Django configuration
- Deployed to two platforms simultaneously
### Results
R****.com - SUCCESS
- Build: Successful (52 seconds)
- Deployment: Successful
- Status: Live and running without errors
- All middleware loaded correctly
- All templates configured correctly
- Cookie Consent system working
- GA4 tracking functional
Railway - FAILURE
- Build: Successful
- Deployment: Crashes with middleware errors
- Status: Down
- Error: Reports ALL middleware missing despite being present in code
- Same errors persist across Nixpacks, Railpack, and Dockerfile
### Conclusion
This is definitively a Railway platform bug, not a code issue.
The exact same code that:
-
Works perfectly locally
-
Deploys successfully on R*****.com
-
Fails consistently on Railway
### Request
Since the code is proven to work on other platforms, this is clearly a Railway-specific caching/volume persistence issue. Could you please:
1. Manually clear all persistent caches for service planmycamper.de
2. Delete and recreate the service if cache clearing doesn't work
3. Investigate your volume persistence mechanism - it's caching old Python module imports
I'm a PRO plan customer paying €20/month and my production site has been down due to this platform bug.
Thank you for your urgent attention to this matter.
tjayfl
## UPDATE: Cross-Platform Testing Confirms Railway Platform BugI've conducted cross-platform testing to definitively isolate the issue:### Test Setup- Same codebase (commit 13ab600)- Same requirements.txt- Same Django configuration- Deployed to two platforms simultaneously### ResultsR****.com - SUCCESS- Build: Successful (52 seconds)- Deployment: Successful- Status: Live and running without errors- All middleware loaded correctly- All templates configured correctly- Cookie Consent system working- GA4 tracking functionalRailway - FAILURE- Build: Successful- Deployment: Crashes with middleware errors- Status: Down- Error: Reports ALL middleware missing despite being present in code- Same errors persist across Nixpacks, Railpack, and Dockerfile### ConclusionThis is definitively a Railway platform bug, not a code issue.The exact same code that:- Works perfectly locally- Deploys successfully on R*****.com- Fails consistently on Railway### RequestSince the code is proven to work on other platforms, this is clearly a Railway-specific caching/volume persistence issue. Could you please:1. Manually clear all persistent caches for service planmycamper.de2. Delete and recreate the service if cache clearing doesn't work3. Investigate your volume persistence mechanism - it's caching old Python module importsI'm a PRO plan customer paying €20/month and my production site has been down due to this platform bug.Thank you for your urgent attention to this matter.
2 months ago
Hey, you have mentioned to delete and recreate the service, have you already tried to deploy the same service again and see if the caching issue still persists?
uxuz
Hey, you have mentioned to delete and recreate the service, have you already tried to deploy the same service again and see if the caching issue still persists?
2 months ago
Hi @uxuz,
Yes, I've tested exactly that approach and it **confirms the caching issue is environment-specific**:
## What I Did:
1. **Created a new Test Environment** (parallel to Production)
2. **Deployed the exact same code** (commit `1e00536`)
3. **Used a fresh Postgres instance** in the Test Environment
## Results:
**Production Environment (old):**
- ❌ Crashes with "AccountMiddleware must be added to settings.MIDDLEWARE"
- ❌ Reports ALL middleware as missing despite being present in code
- ❌ Persists across multiple deployments and cache-clearing attempts
**Test Environment (new):**
- ✅ Deploys successfully
- ✅ All migrations run
- ✅ All middleware loaded correctly
- ✅ Application running without errors
- ✅ URL: `web-test-planmycamperde.up.railway.app`
## Proof:
**Same code, different environments, different results:**
- GitHub commit: `1e00536` (Add psycopg2-binary for PostgreSQL support)
- Production: Crashes
- Test: Works perfectly
**Deployment logs from Test Environment show:**
Migrations applied successfully
Superuser created
Project templates created
Gunicorn started
## Conclusion:
This definitively proves the Production Environment has a **persistent cache/volume issue** that cannot be cleared through normal means. The Test Environment works flawlessly with the identical codebase.
## Request:
Could you please either:
1. **Clear all persistent caches/volumes** for the Production Environment, or
2. **Confirm this is a known platform issue** so I can migrate Production to the Test Environment
Thank you for your help!2 months ago
##
RESOLVED - Workaround Found
Hi All,
I've successfully resolved the issue using a workaround:
## Solution:
Synced Production Environment with Test Environment - This forced Railway to rebuild everything from scratch and bypassed the persistent cache issue.
## Steps Taken:
1. Created Test Environment (which deployed successfully)
2. Synced Production Environment with Test Environment
3. Production now deploys successfully with all updates
## Current Status:
Production is now live and working
All middleware loaded correctly
Cookie Consent system functional
All features deployed successfully
## Root Cause Confirmed:
The Production Environment had a persistent cache/volume issue that:
- Could not be cleared through normal deployment methods
- Survived NIXPACKS_NO_CACHE=1
- Survived builder changes (Nixpacks → Railpack → Dockerfile)
- Was environment-specific (Test Environment worked immediately)
## Recommendation for Railway Team:
This suggests there may be a deeper caching mechanism at the environment level that can persist corrupted state. Consider investigating:
- Volume persistence between deployments
- Python module import caching
- Environment-level cache that survives normal cache-clearing operations
## Outcome:
While the workaround (environment sync) resolved my immediate issue, this behavior could affect other users. The fact that a fresh environment worked immediately while the old environment persistently failed suggests a platform-level caching bug.
Thank you for your support throughout this process!
Status:
Resolved via workaround
Downtime: ~36 hours total
Final solution: Environment sync
Status changed to Solved uxuz • 2 months ago