Skip to content

datetime.datetime.utcnow() is deprecated #2407

Closed
@grigi

Description

@grigi

Problem Statement

Python 3.12 deprecated datetime.datetime.utcnow():

.pyenv/lib/python3.12/site-packages/sentry_sdk/tracing.py:148: 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).

Solution Brainstorm

Update sentry to use datetime.datetime.now(datetime.UTC) instead of datetime.datetime.utcnow() as suggested.
Some quick testing shows that for this to work on python < 3.11 would have to do datetime.datetime.now(datetime.timezone.utc) instead as the datetime.UTC shortcut was only added in python 3.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions