Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datetime.datetime.utcnow() is deprecated #2407

Closed
grigi opened this issue Oct 3, 2023 · 4 comments · Fixed by #2415
Closed

datetime.datetime.utcnow() is deprecated #2407

grigi opened this issue Oct 3, 2023 · 4 comments · Fixed by #2415
Labels
Good first issue Good for newcomers Hacktoberfest 🎃 Issues eligible for Hacktoberfest!

Comments

@grigi
Copy link

grigi commented Oct 3, 2023

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

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Oct 3, 2023
@getsantry getsantry bot removed the status in GitHub Issues with 👀 Oct 3, 2023
@sentrivana sentrivana added Good first issue Good for newcomers Hacktoberfest 🎃 Issues eligible for Hacktoberfest! labels Oct 3, 2023
@sentrivana sentrivana added this to the Python 3.12 Support milestone Oct 3, 2023
@sentrivana
Copy link
Contributor

sentrivana commented Oct 3, 2023

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!

@mohebmithani
Copy link

Hi @sentrivana can i take this?

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Oct 3, 2023
@rmad17
Copy link
Contributor

rmad17 commented Oct 4, 2023

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?

@sentrivana
Copy link
Contributor

sentrivana commented Oct 4, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good first issue Good for newcomers Hacktoberfest 🎃 Issues eligible for Hacktoberfest!
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants