-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[Bug] datetime.datetime.utcnow()
is deprecated as of Python 3.12
#9791
Comments
You are the king @dataders 👑 Potential solution here: #5267 (comment) |
TLDRIt looks to me like we can preserve the current behavior by updating references to: datetime.utcnow() with datetime.now(timezone.utc).replace(tzinfo=None) RecommendationsShort term, I'd recommend:
Long-term, I'd recommend:
OccurrencesThis shows up in our code base in a lot of places: More detail# compare_datetimes.py
from datetime import timezone, datetime
# To compare/contrast effectively, set your local system time zone to something _different_ than UTC
# Naive datetimes -- beware!
naive_1 = datetime.utcnow() # ❌ current
naive_2 = datetime.now(timezone.utc).replace(tzinfo=None) # ✅ recommended search/replace
naive_3 = datetime.now() # extra beware this one!
# Aware datetimes
aware_1 = datetime.now(timezone.utc) # standardized to UTC
aware_2 = datetime.now().astimezone() # system local time zone
naive = [naive_1, naive_2, naive_3]
aware = [aware_1, aware_2]
for i in naive + aware:
# Format the datetime as a string using the ISO 8601 format
print(i.isoformat()) Run the python script: python compare_datetimes.py Output (using
|
Hello there, I found myself with some spare time during the Easter break and decided to follow through on this issue. Please forgive any impudence🙏 @dbeatty10, I second your thoughts. Found very sensible your comment, about decoupling @dataders, to your helpful diagnose, I just wanted to add that besides if sys.version_info >= (3, 12):
def datetime_utcnow():
return datetime.now(timezone.utc).replace(tzinfo=None)
else:
datetime_utcnow = datetime.utcnow thus saving some characters in the places where UTC time is needed, like this: first_count = now = datetime_utcnow() In a future where But I digress... To get some results firsts, I just want to help with:
With those two goals in mind, I put up fix branch on my fork, all code changes included. The deprecation warnings are gone, except for:
To address the latter, I tried bumping the package version from: Line 58 in 71f3519
to "logbook>=1.5,<1.7.0.post0", However, for reasons I still do not understand, Cheers~ |
Upon closer look, the issue was not that The folk over there have been informed. Until a new release is done on their end, there is not much that can be done for this issue, so I will keep the versions that is pinned currently ( |
Will fix the deprecation warning. Source: dbt-labs/dbt-core#9791 (comment)
This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please comment on the issue or else it will be closed in 7 days. |
Although we are closing this issue as stale, it's not gone forever. Issues can be reopened if there is renewed community interest. Just add a comment to notify the maintainers. |
This issue is a serious pest when you are running in the foreground .. i.e. developer mode without supervisor. It wont affect regular users, but as a developer, when I am looking for my print() statements to display debugging info, it is a real pest to have it all scrolled off the screen with a whole load of unnecessary deprecation warnings about "datetime.datetime.utcnow". Since it will have to be fixed once the method is dropped, would it not be better to fix it while there is time to do the work? |
Is this a new bug in dbt-core?
Current Behavior
Thanks to Talla in #adapter-ecosytem Slack channel for the heads up
Any usage of
datetime.datetime.utcnow()
throws the following deprecation warning in Python 3.12related: dbt-labs/dbt-common#99
Expected Behavior
This shouldn't happen
Steps To Reproduce
Run our unit test suite with Python 3.12
Relevant log output
No response
Environment
Which database adapter are you using with dbt?
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: