fix(cron): coalesce nullable schedule field to dict in job helpers - #70728
Closed
necoweb3 wants to merge 1 commit into
Closed
fix(cron): coalesce nullable schedule field to dict in job helpers#70728necoweb3 wants to merge 1 commit into
necoweb3 wants to merge 1 commit into
Conversation
job.get('schedule', {}).get('kind') only supplies {} as default when the 'schedule' key is absent from the job dictionary. If a job is persisted or passed with an explicit 'schedule': null / None (e.g. from JSON deserialization of corrupted/hand-edited jobs or empty API fields), job.get('schedule', {}) evaluates to None and the subsequent .get('kind') call raises AttributeError: 'NoneType' object has no attribute 'get'.
This crash affected 7 call paths in cron/jobs.py (mark_job_run, claim_dispatch, heartbeat_run_claim, advance_next_run, claim_job_for_fire, get_due_jobs) and 2 call paths in hermes_cli/cron.py (cron_list, _job_action).
Fix: replace job.get('schedule', {}).get(...) with (job.get('schedule') or {}).get(...) across all affected sites in cron/jobs.py and hermes_cli/cron.py.
Adds regression test suite TestNullScheduleTolerance in tests/cron/test_jobs.py.
Collaborator
Duplicate of #61758. Its shared non-dict schedule repair covers these direct-call sites, persists the repair, and also covers resume/update paths. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes an
AttributeError: 'NoneType' object has no attribute 'get'crash when processing cron job records that contain explicit"schedule": null/Nonevalues (e.g., from hand-editedjobs.jsonfiles or serialized null payloads).Root Cause
job.get("schedule", {})only supplies the{}default fallback when the"schedule"key is omitted entirely from the dictionary. When"schedule": nullis present,.get()returnsNone, causing subsequent.get("kind")calls to raise an unhandledAttributeError.Changes
cron/jobs.py:job.get("schedule", {}).get(...)with(job.get("schedule") or {}).get(...)across 7 call sites (mark_job_run,claim_dispatch,heartbeat_run_claim,advance_next_run,claim_job_for_fire,get_due_jobs).job.get("schedule")to{}before passing tocompute_next_run().hermes_cli/cron.py:cron_listand_job_actionto safely resolvescheduleandnext_run_aton records with nullable fields.tests/cron/test_jobs.py:TestNullScheduleToleranceregression test suite coveringmark_job_run,claim_dispatch,advance_next_run,claim_job_for_fire, andget_due_jobswhen encountering"schedule": None.