fix(batch-jobs): serialize datetime objects in batch job logging response

This commit is contained in:
Dawei Gu 2026-05-26 16:13:56 -07:00
parent a645d464e6
commit 8d5c43b766
2 changed files with 12 additions and 2 deletions

View file

@ -267,10 +267,16 @@ class BedrockBatchesHandler:
response = client.get_model_invocation_job(jobIdentifier=batch_id)
if logging_obj is not None:
# boto3 returns native datetime objects for time fields
# (submitTime, endTime, …) and in ResponseMetadata. The
# logging post_call path calls json.dumps() on dict responses,
# which chokes on datetime — so we serialize with default=str.
import json as _json
logging_obj.post_call(
input=batch_id,
api_key="",
original_response=response,
original_response=_json.dumps(response, default=str),
additional_args={"complete_input_dict": {"jobIdentifier": batch_id}},
)

View file

@ -300,7 +300,11 @@ def test_logging_obj_pre_and_post_call_invoked(patched_boto3):
post_kwargs = logging_obj.post_call.call_args.kwargs
assert post_kwargs["input"] == JOB_ARN
assert post_kwargs["original_response"]["jobArn"] == JOB_ARN
# original_response is JSON-serialized (str) because boto3 returns
# datetime objects that json.dumps() cannot handle natively.
import json
parsed = json.loads(post_kwargs["original_response"])
assert parsed["jobArn"] == JOB_ARN
def test_missing_boto3_raises_helpful_import_error():