Skip to content
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

Replace deprecated utcnow() calls with now(timezone.utc) #788

Merged
merged 1 commit into from
Nov 25, 2024
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 demo/metadata_migration/notebooks/bookkeeper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Optional
from enum import Enum
from datetime import datetime
from datetime import datetime, timezone

from pymongo import MongoClient
from nmdc_schema.migrators.migrator_base import MigratorBase
Expand Down Expand Up @@ -47,7 +47,7 @@ def __init__(
@staticmethod
def get_current_timestamp() -> str:
r"""Returns an ISO 8601 timestamp (string) representing the current time in UTC."""
utc_now = datetime.utcnow()
utc_now = datetime.now(timezone.utc)
iso_utc_now = utc_now.isoformat()
return iso_utc_now # e.g. "2024-02-21T04:31:03.115107"

Expand Down
6 changes: 3 additions & 3 deletions nmdc_runtime/api/core/auth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from typing import Optional, Dict

from fastapi import Depends
Expand Down Expand Up @@ -101,9 +101,9 @@ def get_password_hash(password):
def create_access_token(data: dict, expires_delta: Optional[timedelta] = None):
to_encode = data.copy()
if expires_delta:
expire = datetime.utcnow() + expires_delta
expire = datetime.now(timezone.utc) + expires_delta
else:
expire = datetime.utcnow() + timedelta(minutes=15)
expire = datetime.now(timezone.utc) + timedelta(minutes=15)
to_encode.update({"exp": expire})
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
return encoded_jwt
Expand Down
Loading