Preserve sub-second precision when serializing unixTimestamp parameters - #10644
jonathan343 wants to merge 1 commit into
Conversation
Serialize unixTimestamp request parameters with the full sub-second precision the caller provided instead of truncating to whole seconds. Timestamps with a fractional component are now emitted as a fractional value (e.g. 1704110400.123456); whole-second timestamps are unchanged. Ports boto/botocore#3796.
There was a problem hiding this comment.
🟢 Approval recommended
The focused implementation preserves compatibility for whole-second values and includes coverage for fractional and pre-epoch timestamps.
Pull request overview
Preserves fractional precision for Unix timestamp request parameters while retaining integer output for whole seconds.
Changes:
- Serializes fractional Unix timestamps without truncation.
- Supports fractional and negative timestamps in CBOR.
- Adds precision and encoding regression tests.
File summaries
| File | Description |
|---|---|
awscli/botocore/serialize.py |
Updates Unix timestamp and CBOR serialization. |
tests/unit/botocore/test_serialize.py |
Adds timestamp precision and CBOR tests. |
.changes/next-release/bugfix-Serialization-52170.json |
Documents the serialization fix. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| self.UNSIGNED_INT_MAJOR_TYPE, timestamp | ||
| ) | ||
| serialized.extend(initial_byte) | ||
| # Tag 1 permits either an integer or a floating-point epoch seconds |
There was a problem hiding this comment.
code seems fine. just for my understanding why did we have all the _get_additional_info_and_num_bytes logic before and why can it be removed now?
There was a problem hiding this comment.
The _serialize_type_integer we now use calls the same _get_additional_info_and_num_bytes helper under the hood. I'm honestly not sure why this wasn't called in the initial implementation.
But the current behavior is incorrect since we can't serialize negative timestamps. A timestamp value like datetime(1968, 12, 31, 23, 59, 59) currently results in a OverflowError: can't convert negative int to unsigned error which this new approach addresses.
Overview
Ports boto/botocore#3796 and fixes the CLI v2 equivalent of boto/botocore#3255.
CLI v2's vendored botocore serializes
unixTimestamprequest parameters asint(calendar.timegm(...)), dropping any sub-second precision the caller provided. This affects everyjson,rest-json, andsmithy-rpc-v2-cborbody timestamp.iso8601has always carried microseconds, andrfc822(HTTP-date) only supports whole seconds, so only the epoch-seconds format had this issue.This PR preserves the caller's sub-second precision for
unixTimestamp. Whole-second timestamps serialize exactly as before.The CBOR serializer now emits a tagged float64 for fractional timestamps and delegates integer encoding to the shared integer serializer, which also fixes an
OverflowErrorfor pre-1970 timestamps.Testing
Reproduced the scenario from boto/botocore#3255 with
kinesis-video-archived-media list-fragments, pointed at an unreachable endpoint so--debuglogs the serialized body before the send fails:Before (
v2):After:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.