Fix timestamp parsing in job import/export

Use datetime.fromisoformat() instead of strptime with a rigid format
that requires microseconds. When datetime.isoformat() produces
timestamps without microseconds (e.g. "2026-04-02T14:28:40"), the
strptime format "%Y-%m-%dT%H:%M:%S.%f" fails silently, leaving
update_time/create_time as None on the restored model object.

Also guard against None timestamps on the export side to prevent
AttributeError when update_time or create_time is None.

The try/except: pass was silently swallowing parse errors for 5 years,
making it impossible to debug when timestamps failed to restore. Just
check for key presence instead — if the value exists but is malformed,
let it fail loudly.
These fields are required by downstream code, so silently skipping
them just delays the failure. Let KeyError or ValueError surface
at the actual point of failure.

Fixes https://github.com/galaxyproject/galaxy/issues/22371
This commit is contained in:
mvdbeek
2026-04-02 19:14:20 +02:00
parent 22c1e0e59c
commit 6dfc44056e
+2 -8
View File
@@ -1691,14 +1691,8 @@ class BaseDirectoryImportModelStore(ModelImportStore):
def restore_times(
model_object: Union[model.Job, model.WorkflowInvocation, model.WorkflowInvocationStep], attrs: dict[str, Any]
) -> None:
try:
model_object.create_time = datetime.datetime.strptime(attrs["create_time"], "%Y-%m-%dT%H:%M:%S.%f")
except Exception:
pass
try:
model_object.update_time = datetime.datetime.strptime(attrs["update_time"], "%Y-%m-%dT%H:%M:%S.%f")
except Exception:
pass
model_object.create_time = datetime.datetime.fromisoformat(attrs["create_time"])
model_object.update_time = datetime.datetime.fromisoformat(attrs["update_time"])
class DirectoryImportModelStore1901(BaseDirectoryImportModelStore):