Skip to content

Commit 2a89661

Browse files
committed
refactor(admin): replace deprecated datetime.utcnow() (#772)
Python 3.12 deprecated `datetime.utcnow()` in favour of the timezone-aware `datetime.now(datetime.UTC)`. Drop the `.replace(tzinfo=None)` that stripped the timezone from `last_activity` to make it match the naive `utcnow()` result. Both `last_activity` (parsed with `%z`) and the new `datetime.now(datetime.UTC)` are now timezone-aware UTC values, so the subtraction yields the same `timedelta` as before.
1 parent b06de62 commit 2a89661

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

  • reana_server/reana_admin

reana_server/reana_admin/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,8 +1049,8 @@ def interactive_session_cleanup(
10491049

10501050
last_activity = datetime.datetime.strptime(
10511051
session_status["last_activity"], "%Y-%m-%dT%H:%M:%S.%f%z"
1052-
).replace(tzinfo=None)
1053-
duration = datetime.datetime.utcnow() - last_activity
1052+
)
1053+
duration = datetime.datetime.now(datetime.UTC) - last_activity
10541054
if duration.days >= days:
10551055
if dry_run:
10561056
click.echo(

0 commit comments

Comments
 (0)