<@ULVA73B9P> why am i getting htis error Dec 11 1...
# ask-marvin
c
@Marvin why am i getting htis error Dec 11 173423 container-apps prefect[162006]: File "/home/aspire/prefect-venv/lib/python3.11/site-packages/prefect/server/api/workers.py", line 403, in get_scheduled_flow_runs Dec 11 173423 container-apps prefect[162006]: File "/home/aspire/prefect-venv/lib/python3.11/site-packages/prefect/server/models/workers.py", line 324, in get_scheduled_flow_runs Dec 11 173423 container-apps prefect[162006]: File "/home/aspire/prefect-venv/lib/python3.11/site-packages/prefect/server/database/query_components.py", line 270, in get_scheduled_flow_runs_from_work_pool Dec 11 173423 container-apps prefect[162006]: File "/home/aspire/prefect-venv/lib/python3.11/site-packages/jinja2/environment.py", line 1016, in get_template Dec 11 173423 container-apps prefect[162006]: return self._load_template(name, globals) Dec 11 173423 container-apps prefect[162006]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Dec 11 173423 container-apps prefect[162006]: File "/home/aspire/prefect-venv/lib/python3.11/site-packages/jinja2/environment.py", line 975, in _load_template Dec 11 173423 container-apps prefect[162006]: template = self.loader.load(self, name, self.make_globals(globals)) Dec 11 173423 container-apps prefect[162006]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Dec 11 173423 container-apps prefect[162006]: File "/home/aspire/prefect-venv/lib/python3.11/site-packages/jinja2/loaders.py", line 126, in load Dec 11 173423 container-apps prefect[162006]: source, filename, uptodate = self.get_source(environment, name) Dec 11 173423 container-apps prefect[162006]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Dec 11 173423 container-apps prefect[162006]: File "/home/aspire/prefect-venv/lib/python3.11/site-packages/jinja2/loaders.py", line 380, in get_source Dec 11 173423 container-apps prefect[162006]: raise TemplateNotFound(template) Dec 11 173423 container-apps prefect[162006]: jinja2.exceptions.TemplateNotFound: postgres/get-runs-from-worker-queues.sql.jinja
m
thought for 192.2 seconds
Thanks for sharing the traceback — that error means the Prefect server tried to load a Jinja2 SQL template used to fetch scheduled flow runs, but the template file isn’t present in your runtime. What’s happening - The server endpoint that workers call to fetch scheduled runs renders a Jinja2 SQL template based on your DB dialect. - For Postgres it looks for:
prefect/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:
Copy code
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:
Copy code
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:
Copy code
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:
Copy code
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)