Skip to content

Commit a5c1f4e

Browse files
authored
Fix DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. (#1261)
* Fix DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC) * Update release notes and bumped the version * Fix CI issue realated to actions/setup-python#962
1 parent 4b86304 commit a5c1f4e

File tree

5 files changed

+14
-5
lines changed

5 files changed

+14
-5
lines changed

.github/workflows/test.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ on:
88
jobs:
99
test:
1010

11-
runs-on: ubuntu-latest
11+
runs-on: ubuntu-22.04
1212
strategy:
1313
matrix:
14-
python-version: ['3.7', '3.8', '3.9', '3.10', 'pypy-3.8']
14+
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11' ,'3.12', 'pypy-3.8']
1515

1616
steps:
1717
- uses: actions/checkout@v2

docs/release_notes.rst

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
Release Notes
44
=============
55

6+
v6.0.2
7+
------
8+
9+
Fixes:
10+
11+
* Fix a warning about `datetime.utcfromtimestamp` deprecation (:pr:`1261`)
12+
613
v6.0.1
714
------
815

pynamodb/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
"""
88
__author__ = 'Jharrod LaFon'
99
__license__ = 'MIT'
10-
__version__ = '6.0.1'
10+
__version__ = '6.0.2'

pynamodb/attributes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ def _normalize(self, value):
825825
value = calendar.timegm(value.utctimetuple())
826826
else:
827827
raise ValueError("TTLAttribute value must be a timedelta or datetime")
828-
return datetime.utcfromtimestamp(value).replace(tzinfo=timezone.utc)
828+
return datetime.fromtimestamp(value, tz=timezone.utc)
829829

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

851851

852852
class UTCDateTimeAttribute(Attribute[datetime]):

setup.py

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
'Programming Language :: Python :: 3.8',
3434
'Programming Language :: Python :: 3.9',
3535
'Programming Language :: Python :: 3.10',
36+
'Programming Language :: Python :: 3.11',
37+
'Programming Language :: Python :: 3.12',
3638
'License :: OSI Approved :: MIT License',
3739
],
3840
extras_require={

0 commit comments

Comments
 (0)