{"record":{"id":"24fd10f0316e3077","repo":"fastapi/fastapi","slug":"no-pr-number-available","errorCode":null,"errorMessage":"No PR number available","messagePattern":"No PR number available","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"scripts/notify_translations.py","lineNumber":326,"sourceCode":"    if settings.debug:\n        logging.basicConfig(level=logging.DEBUG)\n    else:\n        logging.basicConfig(level=logging.INFO)\n    logging.debug(f\"Using config: {settings.model_dump_json()}\")\n    g = Github(settings.github_token.get_secret_value())\n    repo = g.get_repo(settings.github_repository)\n    if not settings.github_event_path.is_file():\n        raise RuntimeError(\n            f\"No github event file available at: {settings.github_event_path}\"\n        )\n    contents = settings.github_event_path.read_text(\"utf-8\")\n    github_event = PartialGitHubEvent.model_validate_json(contents)\n    logging.info(f\"Using GitHub event: {github_event}\")\n    number = (\n        github_event.pull_request and github_event.pull_request.number\n    ) or settings.number\n    if number is None:\n        raise RuntimeError(\"No PR number available\")\n    number = cast(int, number)\n\n    # Avoid race conditions with multiple labels\n    sleep_time = random.random() * 10  # random number between 0 and 10 seconds\n    logging.info(\n        f\"Sleeping for {sleep_time} seconds to avoid \"\n        \"race conditions and multiple comments\"\n    )\n    time.sleep(sleep_time)\n\n    # Get PR\n    logging.debug(f\"Processing PR: #{number}\")\n    pr = repo.get_pull(number)\n    label_strs = {label.name for label in pr.get_labels()}\n    langs = []\n    for label in label_strs:\n        if label.startswith(\"lang-\") and not label == lang_all_label:\n            langs.append(label[5:])","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/fastapi/fastapi/blob/a1fa70d4237d50aae6586a0d9b229df583463d21/scripts/notify_translations.py#L308-L344","documentation":"Control-flow guard in notify_translations.main (scripts/notify_translations.py:324-327): the script needs a PR number to post comments; it takes it from the GitHub event payload (github_event.pull_request.number) or falls back to settings.number (the PR_NUMBER-style env var). If both are absent — the event is not a pull_request event and no number was configured — it raises RuntimeError('No PR number available').","triggerScenarios":"The workflow triggers on non-PR events (push, issue_comment, schedule) so the event JSON has no pull_request node, and no explicit number env var is set; or the event shape changed so pull_request.number is null.","commonSituations":"A workflow's 'on:' block widened to include pushes/schedules while reusing this script; manual workflow_dispatch runs without a number input; event payloads from fork PRs where some fields are trimmed.","solutions":["Restrict the workflow to pull_request events (on: pull_request: types: [...] ) so the event always carries pull_request.number.","For manual dispatch, provide the PR number via the workflow's 'number' input mapped to the corresponding env var read by Settings.","If you must support other events, add an upfront guard in the workflow (if: github.event_name == 'pull_request') before calling the script.","Log the event JSON when debugging to confirm which shape arrived."],"exampleFix":"# before (.github/workflows/notify.yml)\non: [push, pull_request]  # push events have no PR number -> RuntimeError\n\n# after\non:\n  pull_request:\n    types: [opened, synchronize, reopened]","handlingStrategy":"validation","validationCode":"import json, os\nfrom pathlib import Path\n\ndef resolve_pr_number() -> int | None:\n    p = os.environ.get(\"GITHUB_EVENT_PATH\")\n    if p and Path(p).is_file():\n        n = json.loads(Path(p).read_text(\"utf-8\")).get(\"pull_request\", {}).get(\"number\")\n        if n:\n            return int(n)\n    env_num = os.environ.get(\"PR_NUMBER\")  # mirror of Settings.number\n    return int(env_num) if env_num and env_num.isdigit() else None","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Gate the workflow on pull_request events (or add if: github.event_name == 'pull_request').","For workflow_dispatch, expose a required 'number' input mapped to the script's Settings field.","Log the parsed event name/number at job start so context mismatches are obvious."],"tags":["fastapi","ci","github-actions","configuration","scripts"],"backgroundTag":null,"analyzedSha":"a1fa70d4237d50aae6586a0d9b229df583463d21","analyzedAt":"2026-08-14T19:41:58.359Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}