fix(cron): handle bare-list jobs.json in load_jobs()#30208
Closed
aim-ma-sourcing wants to merge 1 commit into
Closed
fix(cron): handle bare-list jobs.json in load_jobs()#30208aim-ma-sourcing wants to merge 1 commit into
aim-ma-sourcing wants to merge 1 commit into
Conversation
load_jobs() assumed jobs.json is always a dict {"jobs": [...]}, but bare
list format [...] can appear from:
- distribution installs (shutil.copytree copies cron/ as-is)
- quick snapshot restores (raw file copy)
- older hermes versions or manual edits
This caused 'list' object has no attribute 'get' on every cronjob(action='list')
call, breaking all cron management until the file was manually fixed.
curator_backup.py already handled both formats (line 424), but the
primary load_jobs() did not. Now load_jobs() detects bare lists and
auto-repairs them to canonical {"jobs": [...]} format on read.
Collaborator
Contributor
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.
Problem
load_jobs()incron/jobs.pyassumesjobs.jsonis always in the canonical dict format{"jobs": [...]}, callingdata.get("jobs", [])unconditionally. However, bare list format[...]can appear from:shutil.copytreecopiescron/as-is during_copy_dist_payload()shutil.copy2does raw file copy inrestore_quick_snapshot()When
jobs.jsoncontains a bare list, everycronjob(action='list')call fails with:This breaks all cron management until the file is manually repaired.
Fix
Add
isinstance(data, list)checks toload_jobs()in both the normal parse path and theJSONDecodeErrorretry path. When a bare list is detected, auto-repair it to the canonical{"jobs": [...]}format viasave_jobs().Note:
curator_backup.pyalready handled both formats (line 424:# accept both that shape and a bare list for forward compat), but the primaryload_jobs()did not.Testing
Verified locally:
jobs.jsonload_jobs()— returned correct job datajobs.jsonwas auto-repaired to{"jobs": [...]}formatcronjob(action='list')works correctly after repair