Skip to content

Fix DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. #1261

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

Merged
merged 3 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ on:
jobs:
test:

runs-on: ubuntu-latest
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', 'pypy-3.8']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11' ,'3.12', 'pypy-3.8']

steps:
- uses: actions/checkout@v2
Expand Down
7 changes: 7 additions & 0 deletions docs/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
Release Notes
=============

v6.0.2
------

Fixes:

* Fix a warning about `datetime.utcfromtimestamp` deprecation (:pr:`1261`)

v6.0.1
------

Expand Down
2 changes: 1 addition & 1 deletion pynamodb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
"""
__author__ = 'Jharrod LaFon'
__license__ = 'MIT'
__version__ = '6.0.1'
__version__ = '6.0.2'
4 changes: 2 additions & 2 deletions pynamodb/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ def _normalize(self, value):
value = calendar.timegm(value.utctimetuple())
else:
raise ValueError("TTLAttribute value must be a timedelta or datetime")
return datetime.utcfromtimestamp(value).replace(tzinfo=timezone.utc)
return datetime.fromtimestamp(value, tz=timezone.utc)

def __set__(self, instance, value):
"""
Expand All @@ -846,7 +846,7 @@ def deserialize(self, value):
Deserializes a timestamp (Unix time) as a UTC datetime.
"""
timestamp = json.loads(value)
return datetime.utcfromtimestamp(timestamp).replace(tzinfo=timezone.utc)
return datetime.fromtimestamp(timestamp, tz=timezone.utc)


class UTCDateTimeAttribute(Attribute[datetime]):
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'License :: OSI Approved :: MIT License',
],
extras_require={
Expand Down
Loading