Skip to content

Conversation

@NicoHinderling
Copy link
Contributor

While looking through GCP logs, I see this noisy log showing up a ton:

/usr/src/sentry/src/sentry/utils/dates.py:193: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).

lets address it

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Sep 15, 2025
cursor[bot]

This comment was marked as outdated.

@codecov
Copy link

codecov bot commented Sep 15, 2025

✅ All tests passed

cursor[bot]

This comment was marked as outdated.

@NicoHinderling NicoHinderling force-pushed the update-datetime-get-rid-of-noisy-log branch from 7216c73 to 6004b97 Compare September 15, 2025 22:00
@NicoHinderling NicoHinderling changed the title chore: Update datetime method to avoid noisy log chore: Update datetime method to clean up noisy log Sep 15, 2025
# Need to support timezone-aware and naive datetimes since
# Snuba API only deals in naive UTC
now = datetime.now(UTC) if start.tzinfo else datetime.utcnow()
now = datetime.now(UTC) if start.tzinfo else datetime.now(UTC).replace(tzinfo=None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, wouldn't replacing the tzinfo with None remove the UTC?

In other words: in the existing definition:

datetime.now(UTC) if start.tzinfo else datetime.utcnow()

How are datetime.now(UTC) and datetime.utcnow() different?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, digging in I see that replace does leave the time alone, so this shouldn't be a problem. LGTM.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hehe yeah I was confused by this too

@NicoHinderling NicoHinderling merged commit a76f392 into master Oct 27, 2025
64 checks passed
@NicoHinderling NicoHinderling deleted the update-datetime-get-rid-of-noisy-log branch October 27, 2025 17:02
priscilawebdev pushed a commit that referenced this pull request Oct 28, 2025
While looking through GCP logs, I see this noisy log showing up a ton:

```
/usr/src/sentry/src/sentry/utils/dates.py:193: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
```

lets address it
shashjar pushed a commit that referenced this pull request Nov 4, 2025
While looking through GCP logs, I see this noisy log showing up a ton:

```
/usr/src/sentry/src/sentry/utils/dates.py:193: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
```

lets address it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants