Skip to content

datetime.datetime.utcnow() is deprecated #2407

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

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀on Oct 3, 2023
  2. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀on Oct 3, 2023
  3. added this to the Python 3.12 Support milestone on Oct 3, 2023
  4. sentrivana commented on Oct 3, 2023

    @sentrivana
    Contributor

    Good catch @grigi! I've added this to the list of things we should tackle in order to support 3.12.

    If you or anyone reading this feels like it, PRs are very welcome!

  5. mohebmithani commented on Oct 3, 2023

    @mohebmithani

    Hi @sentrivana can i take this?

  6. moved this to Waiting for: Product Owner in GitHub Issues with 👀on Oct 3, 2023
  7. rmad17 commented on Oct 4, 2023

    @rmad17
    Contributor

    I made the changes, but unfortunately, realized after that I could not push the code to a new branch. What is the process to open a PR?

  8. sentrivana commented on Oct 4, 2023

    @sentrivana
    Contributor

    Hey @mohebmithani, no need to ask, feel free to just submit a PR! But seems like @rmad17 already has a solution for this issue.

    Awesome @rmad17! The gist is that you need to make the changes on a fork of this repo:

    • fork the getsentry/sentry-python repo
    • clone the forked repo to work on it locally
    • push a new branch with the changes to your fork
    • and finally open a PR from your fork (and your branch) against this repo's master branch

    We should do a better job outlining this in our CONTRIBUTING.md -- I will look into that. Let me know if you need more pointers!

  9. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀on Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions