chase albright
12/11/2025, 5:45 PMMarvin
12/11/2025, 5:45 PMMarvin
12/11/2025, 5:48 PMprefect/server/database/sql/postgres/get-runs-from-worker-queues.sql.jinja
- Your runtime can’t find that file, so Jinja2 raises TemplateNotFound.
Why this typically happens
- The SQL templates are package data inside Prefect. If you’re using a custom container, PyInstaller/zipapp/PEX, or a wheel built without including package data, those files may be missing at runtime.
- We’ve seen this with custom builds or certain packaging setups; the official Prefect builds include these files.
Quick checks
Run this inside the same venv/container where the server is running to confirm the files are missing:
python - <<'PY'
import importlib.resources as r
from prefect.server import database
p = r.files(database) / 'sql' / 'postgres'
print('Template dir exists:', p.is_dir())
if p.is_dir():
print('Contents:', [x.name for x in p.iterdir()])
else:
print('Missing template directory')
PY
How to fix
- If you can, upgrade/reinstall Prefect cleanly so the package data is present:
pip install --upgrade --no-cache-dir --force-reinstall prefect
- If you’re using a custom Docker image, rebuild it from a clean base and install Prefect from PyPI (don’t copy an already-built wheel that might be missing data). Example:
FROM python:3.11-slim
RUN pip install --no-cache-dir prefect
- If you bundle your app (PyInstaller/PEX/zipapp), ensure package data for prefect.server.database.sql is collected. For PyInstaller:
pyinstaller --collect-data=prefect.server.database your_entrypoint.py
- As a sanity check, using an official image like prefecthq/prefect:3-latest for the server avoids this packaging issue.
References (source)
- Template loader in Prefect: query_components.py
- The expected Postgres templates: SQL templates (postgres)
- Call path that triggers the load: models/workers.py
To help narrow this down, could you share:
- Prefect version (prefect version)
- How Prefect was installed (pip, Docker image, PyInstaller, etc.)
- What image/environment you’re running in (the log mentions “container-apps”, is this Azure Container Apps with a custom image?)
- Which database backend the server is using (looks like Postgres from the error)