tiangolo/fastapi · error · RuntimeError

No PR number available

Error message

No PR number available

What it means

Raised by notify_translations.main() at scripts/notify_translations.py:326 when no PR number can be determined. The number is computed as (github_event.pull_request and github_event.pull_request.number) or settings.number at scripts/notify_translations.py:322-324. Both being None/0 means there is no PR to process.

Source

Thrown at scripts/notify_translations.py:326

    if settings.debug:
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.INFO)
    logging.debug(f"Using config: {settings.model_dump_json()}")
    g = Github(settings.github_token.get_secret_value())
    repo = g.get_repo(settings.github_repository)
    if not settings.github_event_path.is_file():
        raise RuntimeError(
            f"No github event file available at: {settings.github_event_path}"
        )
    contents = settings.github_event_path.read_text("utf-8")
    github_event = PartialGitHubEvent.model_validate_json(contents)
    logging.info(f"Using GitHub event: {github_event}")
    number = (
        github_event.pull_request and github_event.pull_request.number
    ) or settings.number
    if number is None:
        raise RuntimeError("No PR number available")
    number = cast(int, number)

    # Avoid race conditions with multiple labels
    sleep_time = random.random() * 10  # random number between 0 and 10 seconds
    logging.info(
        f"Sleeping for {sleep_time} seconds to avoid "
        "race conditions and multiple comments"
    )
    time.sleep(sleep_time)

    # Get PR
    logging.debug(f"Processing PR: #{number}")
    pr = repo.get_pull(number)
    label_strs = {label.name for label in pr.get_labels()}
    langs = []
    for label in label_strs:
        if label.startswith("lang-") and not label == lang_all_label:
            langs.append(label[5:])

View on GitHub (pinned to 3e8d1526d8)

Solutions

  1. Constrain the workflow to pull_request / pull_request_target triggers so the event payload carries a pull_request.number.
  2. For manual runs, set the NUMBER env var to the target PR number.
  3. Inspect the event JSON at GITHUB_EVENT_PATH to confirm pull_request.number is present and non-null.

Example fix

# before — workflow triggers on push
on: [push]
# after — trigger on pull request events
on:
  pull_request:
    types: [labeled, unlabeled, closed]
Defensive patterns

Strategy: validation

Validate before calling

import os, json

def pr_number_available() -> bool:
    ev = os.environ.get("GITHUB_EVENT_PATH")
    if ev:
        data = json.loads(open(ev).read())
        if data.get("pull_request", {}).get("number"):
            return True
    return bool(os.environ.get("NUMBER"))

Try / catch

if number is None:
    logging.error("No PR number in event payload and NUMBER env var unset")
    sys.exit(1)

Prevention

When it happens

Trigger: The GITHUB_EVENT_PATH payload is for a non-PR event (push, issue, schedule) so github_event.pull_request is None, AND the NUMBER env var (settings.number fallback) is unset. Also fires if the PR payload exists but its 'number' field is null.

Common situations: Job triggered on the wrong event (e.g. on: push instead of on: pull_request). Workflow_dispatch run where the user forgot to pass NUMBER. The event payload structure changed and pull_request.number is missing.

Related errors


AI-assisted analysis of tiangolo/fastapi@3e8d1526d8 (2026-08-11). Data as JSON: /api/errors/089037db6e10c036. Report an issue: GitHub.