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

[ENH] Replace deprecated utcnow() invocations #1059

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion conda-store-server/conda_store_server/_internal/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ def update_packages(self, db, subdirs=None):

logger.info(f"DONE for architecture : {architecture}")

self.last_update = datetime.datetime.utcnow()
self.last_update = datetime.datetime.now(tz=datetime.timezone.utc)
db.commit()
logger.info("update packages DONE ")

Expand Down
19 changes: 11 additions & 8 deletions conda-store-server/conda_store_server/_internal/worker/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def append_to_logs(db: Session, conda_store, build, logs: typing.Union[str, byte

def set_build_started(db: Session, build: orm.Build):
build.status = schema.BuildStatus.BUILDING
build.started_on = datetime.datetime.utcnow()
build.started_on = datetime.datetime.now(tz=datetime.timezone.utc)
db.commit()


Expand All @@ -83,7 +83,7 @@ def set_build_failed(
):
build.status = schema.BuildStatus.FAILED
build.status_info = status_info
build.ended_on = datetime.datetime.utcnow()
build.ended_on = datetime.datetime.now(tz=datetime.timezone.utc)
db.commit()


Expand All @@ -92,13 +92,13 @@ def set_build_canceled(
):
build.status = schema.BuildStatus.CANCELED
build.status_info = status_info
build.ended_on = datetime.datetime.utcnow()
build.ended_on = datetime.datetime.now(tz=datetime.timezone.utc)
db.commit()


def set_build_completed(db: Session, conda_store, build: orm.Build):
build.status = schema.BuildStatus.COMPLETED
build.ended_on = datetime.datetime.utcnow()
build.ended_on = datetime.datetime.now(tz=datetime.timezone.utc)

directory_build_artifact = orm.BuildArtifact(
build_id=build.id,
Expand Down Expand Up @@ -162,7 +162,10 @@ def build_cleanup(
and str(build.id) not in build_active_tasks
and (
build.started_on
< (datetime.datetime.utcnow() - datetime.timedelta(seconds=5))
< (
datetime.datetime.now(tz=datetime.timezone.utc)
- datetime.timedelta(seconds=5)
)
)
):
conda_store.log.warning(
Expand Down Expand Up @@ -194,7 +197,7 @@ def build_conda_environment(db: Session, conda_store, build):
db,
conda_store,
build,
f"starting build of conda environment {datetime.datetime.utcnow()} UTC\n",
f"starting build of conda environment {datetime.datetime.now(tz=datetime.timezone.utc)} UTC\n",
)

settings = conda_store.get_settings(
Expand Down Expand Up @@ -337,7 +340,7 @@ def build_conda_environment(db: Session, conda_store, build):


def solve_conda_environment(db: Session, conda_store, solve: orm.Solve):
solve.started_on = datetime.datetime.utcnow()
solve.started_on = datetime.datetime.now(tz=datetime.timezone.utc)
db.commit()

_, locker = conda_store.lock_plugin()
Expand All @@ -353,7 +356,7 @@ def solve_conda_environment(db: Session, conda_store, solve: orm.Solve):
solve_id=solve.id,
)

solve.ended_on = datetime.datetime.utcnow()
solve.ended_on = datetime.datetime.now(tz=datetime.timezone.utc)
db.commit()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def task_delete_build(self, build_id):
delete_build_artifact(db, conda_store, build_artifact)

# Updates build size and marks build as deleted
build.deleted_on = datetime.datetime.utcnow()
build.deleted_on = datetime.datetime.now(tz=datetime.timezone.utc)
build.size = 0

db.commit()
Expand Down
6 changes: 3 additions & 3 deletions conda-store-server/conda_store_server/conda_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def delete_namespace(self, db: Session, namespace: str):
if namespace is None:
raise CondaStoreError(f"namespace={namespace} does not exist")

utcnow = datetime.datetime.utcnow()
utcnow = datetime.datetime.now(tz=datetime.timezone.utc)
namespace.deleted_on = utcnow
for environment_orm in namespace.environments:
environment_orm.deleted_on = utcnow
Expand Down Expand Up @@ -463,7 +463,7 @@ def delete_environment(self, db: Session, namespace: str, name: str):
f"environment namespace={namespace} name={name} does not exist"
)

utcnow = datetime.datetime.utcnow()
utcnow = datetime.datetime.now(tz=datetime.timezone.utc)
environment.deleted_on = utcnow
for build in environment.builds:
build.deleted_on = utcnow
Expand Down Expand Up @@ -492,7 +492,7 @@ def delete_build(self, db: Session, build_id: int):
]:
raise CondaStoreError("cannot delete build since not finished building")

build.deleted_on = datetime.datetime.utcnow()
build.deleted_on = datetime.datetime.now(tz=datetime.timezone.utc)
db.commit()

self.celery_app
Expand Down
5 changes: 4 additions & 1 deletion conda-store-server/conda_store_server/server/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,10 @@ async def post_login_method(
domain=self.cookie_domain,
# set cookie to expire at same time as jwt
max_age=int(
(authentication_token.exp - datetime.datetime.utcnow()).total_seconds()
(
authentication_token.exp
- datetime.datetime.now(tz=datetime.timezone.utc)
).total_seconds()
),
)
return response
Expand Down
2 changes: 1 addition & 1 deletion conda-store-server/conda_store_server/server/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

def _datetime_factory(offset: datetime.timedelta):
"""Utcnow datetime + timezone as string"""
return datetime.datetime.utcnow() + offset
return datetime.datetime.now(tz=datetime.timezone.utc) + offset


RoleBindings: TypeAlias = Dict[
Expand Down
8 changes: 4 additions & 4 deletions conda-store-server/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ def seed_conda_store(db, conda_store):

# for testing purposes make build 4 complete
build = api.get_build(db, build_id=4)
build.started_on = datetime.datetime.utcnow()
build.ended_on = datetime.datetime.utcnow()
build.started_on = datetime.datetime.now(tz=datetime.timezone.utc)
build.ended_on = datetime.datetime.now(tz=datetime.timezone.utc)
build.status = schema.BuildStatus.COMPLETED
db.commit()
return db
Expand Down Expand Up @@ -276,8 +276,8 @@ def seed_conda_store_big(db, conda_store):

# for testing purposes make build 4 complete
build = api.get_build(db, build_id=4)
build.started_on = datetime.datetime.utcnow()
build.ended_on = datetime.datetime.utcnow()
build.started_on = datetime.datetime.now(tz=datetime.timezone.utc)
build.ended_on = datetime.datetime.now(tz=datetime.timezone.utc)
build.status = schema.BuildStatus.COMPLETED
db.commit()
return db
Expand Down
3 changes: 2 additions & 1 deletion conda-store-server/tests/server/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def test_expired_token():
token = authentication.encrypt_token(
AuthenticationToken(
primary_namespace="default",
exp=datetime.datetime.utcnow() - datetime.timedelta(hours=1),
exp=datetime.datetime.now(tz=datetime.timezone.utc)
- datetime.timedelta(hours=1),
role_bindings={
"default/*": ["viewer"],
"e*/e*": ["admin"],
Expand Down
Loading