mobileBackupplist: fix 'datetime is not JSON serializable' crash#1617
Merged
Conversation
The generic 'Value' column holds raw plist values, several of which are datetime objects (date, RestoreDate, FileTransferStartDate, RestoreStartDate, PreFlightStartDate, dateCreated). Since the column is not datetime-typed, LAVA's lava_insert_sqlite_data does json.dumps(value), which raised 'Object of type datetime is not JSON serializable' and aborted the artifact. Convert datetime values to a UTC string (plist <date> is UTC) and bytes to hex before appending; other JSON-serializable types are unchanged. pylint 10.00; runtime-tested a plist with datetime/bytes/normal values - every output value is now json.dumps-able.
LAVA's lava_insert_sqlite_data only json.dumps() dict/list values, so the actual crash is a datetime nested inside a list/dict value (e.g. 'errors'), not just a top-level one. json.dumps such values in the artifact with default=str so nested datetimes/bytes are serialized too, in addition to the top-level datetime->UTC-string / bytes->hex handling.
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
The generic Value column holds raw plist values, and several keys (
date,RestoreDate,FileTransferStartDate,RestoreStartDate,PreFlightStartDate,dateCreated) are datetime objects. Because the column isn't datetime-typed, LAVA serializes non-simple values withjson.dumps, which can't encode a datetime — aborting the artifact once a backup record had a date.Fix
Convert datetime values to a UTC string (plist
<date>is UTC) and bytes to hex before appending; other JSON-serializable types are unchanged.Validation
json.dumps-able (no crash).