Skip to content

fix(cron): import run_job in _run_cron_tracked to fix NameError - #1329

Closed
zichen0116 wants to merge 1 commit into
nesquena:masterfrom
zichen0116:fix/cron-run_job-nameerror
Closed

zichen0116 wants to merge 1 commit into
nesquena:masterfrom
zichen0116:fix/cron-run_job-nameerror

Conversation

@zichen0116

Copy link
Copy Markdown
Contributor

Description

Fixes #1310: Manual cron job execution crashes with NameError: name 'run_job' is not defined.

The _run_cron_tracked() function calls run_job(job) but run_job was never imported. The function is defined at line 95 in api/routes.py, but run_job is only imported locally inside _handle_cron_run() (line 3503).

Fix

Added from cron.scheduler import run_job at the top of _run_cron_tracked() function body, matching the existing import pattern used elsewhere in the file.

Related

Fixes nesquena#1310: Manual cron run crashes with NameError because
_run_cron_tracked() calls run_job() without importing it.
@nesquena-hermes

Copy link
Copy Markdown
Collaborator

Heads up: this is the third PR proposing the same one-line fix for #1310 — see #1312 (fecolinhares) and #1317 (jasonjcwu). All three add from cron.scheduler import run_job inside _run_cron_tracked() to mirror the existing local-import pattern in _handle_cron_run() at line 3503.

The diagnosis is correct and matches the bug surface in master:

  • api/routes.py line 95–100: _run_cron_tracked(job) calls run_job(job) with no module-level or function-level import of run_job in scope
  • _handle_cron_run() line 3502–3514 imports run_job locally, then spawns _run_cron_tracked in a daemon thread — so the NameError only triggers when the wrapper actually runs, not at import time, which is why CI passed

We will pick one of the three to merge and credit all authors via Co-authored-by trailers. #1317 currently leads because it includes an AST-based regression test that asserts the import is actually present inside the function. The patches are otherwise equivalent.

Closing this in favor of #1317 isn't decided yet — leaving open until triage completes. Thanks for the fix.

@nesquena-hermes

Copy link
Copy Markdown
Collaborator

Thanks @zichen0116! 🙏

Closing this in favor of #1317, which lands the same single-line import fix plus AST-based regression tests under tests/test_cron_run_job_import.py. The fix from #1317 ships in release v0.50.245, with #1329 (and #1312) credited in the changelog as parallel discoveries.

Your other two PRs (#1331 .env.example alignment, #1332 Docker HEALTHCHECK) are both in v0.50.245 — thanks for the cleanup pass!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Manual cron run crashes with NameError: run_job is not defined

2 participants