Skip to content

Commit

Permalink
Fix deprecation warning
Browse files Browse the repository at this point in the history
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).
    decoder=lambda t: datetime.datetime.utcfromtimestamp(t / 1000),
  • Loading branch information
Derrick Petzold committed Dec 28, 2024
1 parent 62135c1 commit 321e8c6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
5 changes: 4 additions & 1 deletion aws_log_parser/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,10 @@ class WafLogEntry(LogEntry):
timestamp: datetime.datetime = field(
metadata=config(
encoder=lambda t: datetime.datetime.timestamp(t) * 1000,
decoder=lambda t: datetime.datetime.utcfromtimestamp(t / 1000),
decoder=lambda t: datetime.datetime.fromtimestamp(
t / 1000,
datetime.timezone.utc,
),
)
)
formatVersion: int
Expand Down
11 changes: 10 additions & 1 deletion test/test_parse_waf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@
@pytest.fixture
def base_waf_entry():
return WafLogEntry(
timestamp=datetime.datetime(2018, 8, 8, 0, 44, 30, 589000),
timestamp=datetime.datetime(
2018,
8,
8,
0,
44,
30,
589000,
tzinfo=datetime.timezone.utc,
),
formatVersion=1,
webaclId="385cb038-3a6f-4f2f-ac64-09ab912af590",
terminatingRuleId="Default_Action",
Expand Down
4 changes: 1 addition & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
isolated_build = true
envlist = py{38,39,310,311,312}-pytest{latest},lint
envlist = py{310,311,312}-pytest{latest},lint

[testenv]
allowlist_externals = poetry
Expand All @@ -20,8 +20,6 @@ commands =

[gh-actions]
python =
3.8: py38
3.9: py39
3.10: py310
3.11: py311
3.12: py312,lint

0 comments on commit 321e8c6

Please sign in to comment.