Fix email send crash when worker lacks staticfiles manifest.
Deploy Beta / unit-tests (push) Failing after 25s
Deploy Beta / docker (push) Skipped
Deploy Beta / deploy-beta (push) Skipped

Fall back to an unhashed logo URL if ManifestStaticFilesStorage misses, and run collectstatic in the worker entrypoint.
This commit is contained in:
2026-08-09 06:46:07 -05:00
parent d830f07757
commit aed84b6e11
2 changed files with 33 additions and 5 deletions
+5
View File
@@ -42,5 +42,10 @@ wait_for_database
uv run python manage.py migrate --noinput uv run python manage.py migrate --noinput
# Email branding (and anything else that resolves static URLs) needs the
# ManifestStaticFilesStorage map. Web entrypoint already collectstatics;
# worker must too or hashed lookups raise ValueError.
uv run python manage.py collectstatic --noinput
# dj-queue supervisor (workers + dispatcher + scheduler). Run on ONE host only. # dj-queue supervisor (workers + dispatcher + scheduler). Run on ONE host only.
exec uv run python manage.py dj_queue exec uv run python manage.py dj_queue
+28 -5
View File
@@ -3,13 +3,40 @@
from __future__ import annotations from __future__ import annotations
import html import html
import logging
import re import re
from django.conf import settings from django.conf import settings
from django.contrib.staticfiles.storage import staticfiles_storage from django.contrib.staticfiles.storage import staticfiles_storage
logger = logging.getLogger(__name__)
_URL_RE = re.compile(r"(https?://[^\s<]+)") _URL_RE = re.compile(r"(https?://[^\s<]+)")
_LOGO_STATIC_PATH = "brand/exit_logo.png"
def _absolute_static_url(site_url: str, relative: str) -> str:
"""
Build an absolute URL for a static asset.
Prefer the hashed Manifest URL when available. Fall back to the stable
path when the manifest is missing (dj-queue worker does not run
collectstatic) so sending mail never crashes.
"""
try:
path = staticfiles_storage.url(relative)
except ValueError:
logger.debug(
"staticfiles manifest miss for %s; using unhashed URL", relative
)
static_prefix = settings.STATIC_URL or "/static/"
path = f"{static_prefix}{relative.lstrip('/')}"
if path.startswith("http://") or path.startswith("https://"):
return path
if not path.startswith("/"):
path = f"/{path}"
return f"{site_url}{path}"
def email_brand_context(**extra): def email_brand_context(**extra):
@@ -17,11 +44,7 @@ def email_brand_context(**extra):
if not site_url: if not site_url:
site_url = "https://mkdrealtor.com" site_url = "https://mkdrealtor.com"
logo_path = staticfiles_storage.url("brand/exit_logo.png") logo_url = _absolute_static_url(site_url, _LOGO_STATIC_PATH)
if logo_path.startswith("http://") or logo_path.startswith("https://"):
logo_url = logo_path
else:
logo_url = f"{site_url}{logo_path}"
brand_name = getattr(settings, "SITE_NAME", None) or "Monica Dhillon" brand_name = getattr(settings, "SITE_NAME", None) or "Monica Dhillon"
brand_legal = getattr(settings, "CREDIT_NAME", None) or brand_name brand_legal = getattr(settings, "CREDIT_NAME", None) or brand_name