Skip to content

mobileBackupplist: fix 'datetime is not JSON serializable' crash#1617

Merged
abrignoni merged 2 commits into
mainfrom
fix-mobilebackupplist-datetime
Jun 25, 2026
Merged

mobileBackupplist: fix 'datetime is not JSON serializable' crash#1617
abrignoni merged 2 commits into
mainfrom
fix-mobilebackupplist-datetime

Conversation

@abrignoni

Copy link
Copy Markdown
Owner

Problem

TypeError: Object of type datetime is not JSON serializable
  lavafuncs.py:401  value = json.dumps(value)   (called from the @artifact_processor wrapper)

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 with json.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

  • pylint 10.00/10.
  • Runtime-tested a plist mixing datetime / bytes / bool / list / int / str values — every output value is now json.dumps-able (no crash).

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.
@abrignoni abrignoni merged commit 2f1480d into main Jun 25, 2026
1 check passed
@abrignoni abrignoni deleted the fix-mobilebackupplist-datetime branch June 25, 2026 16:12
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.

1 participant