Skip to content

fix(tracking): replace deprecated datetime.utcnow() in S3 time partition#783

Open
Ghraven wants to merge 1 commit into
apache:mainfrom
Ghraven:fix/s3client-utcnow-deprecation
Open

fix(tracking): replace deprecated datetime.utcnow() in S3 time partition#783
Ghraven wants to merge 1 commit into
apache:mainfrom
Ghraven:fix/s3client-utcnow-deprecation

Conversation

@Ghraven
Copy link
Copy Markdown

@Ghraven Ghraven commented May 20, 2026

What

S3TrackingClient._get_time_partition() in burr/tracking/s3client.py builds the S3 path partition using datetime.datetime.utcnow():

def _get_time_partition(self):
    time = datetime.datetime.utcnow().isoformat()
    return [time[:4], time[5:7], time[8:10], time[11:13], time[14:]]

Why it matters

datetime.utcnow() is deprecated as of Python 3.12 (emits DeprecationWarning) and returns a naive datetime, which is a common source of timezone bugs.

Fix

time = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None).isoformat()

This is timezone-aware at the source (correct UTC) and then drops tzinfo so that .isoformat() produces a byte-identical string to the old call:

old utcnow().isoformat():                          '2026-05-20T18:53:24.500598'
now(utc).replace(tzinfo=None).isoformat():         '2026-05-20T18:53:24.500674'

Using now(utc).isoformat() directly would have appended +00:00 and broken the time[14:] slice, so .replace(tzinfo=None) is intentional to preserve the existing partition format exactly.

Verification

Confirmed the two formats are identical in shape (no offset suffix), so the resulting S3 prefixes (year/month/day/hour/...) are unchanged. File parses and imports. Happy to adjust if you would prefer keeping the offset or a different partition scheme.

_get_time_partition() used datetime.datetime.utcnow(), which is
deprecated in Python 3.12+ and returns a naive datetime. Switched to
datetime.now(timezone.utc).replace(tzinfo=None), which is timezone-aware
at the source and produces a byte-identical isoformat() string (no
+00:00 suffix), so the existing S3 prefix slicing is unchanged.
@github-actions github-actions Bot added the area/tracking Telemetry, tracing, OpenTelemetry label May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/tracking Telemetry, tracing, OpenTelemetry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant