From 9cd93ef72269bcc556ca402aeb9a4180dc4211d4 Mon Sep 17 00:00:00 2001 From: sophia Date: Wed, 11 Dec 2024 09:52:02 -0800 Subject: [PATCH] Add todo for datetime deprecation --- conda-store-server/conda_store_server/_internal/orm.py | 4 ++++ conda-store-server/conda_store_server/_internal/schema.py | 1 + .../conda_store_server/_internal/worker/build.py | 8 ++++++++ conda-store-server/conda_store_server/app.py | 3 +++ conda-store-server/conda_store_server/server/auth.py | 1 + conda-store-server/tests/conftest.py | 1 + conda-store-server/tests/server/test_auth.py | 1 + 7 files changed, 19 insertions(+) diff --git a/conda-store-server/conda_store_server/_internal/orm.py b/conda-store-server/conda_store_server/_internal/orm.py index bf5e767a7..0aa99fca1 100644 --- a/conda-store-server/conda_store_server/_internal/orm.py +++ b/conda-store-server/conda_store_server/_internal/orm.py @@ -173,6 +173,7 @@ def __init__(self, specification, is_lockfile: bool = False): name: Mapped[str] = mapped_column(Unicode(255), nullable=False) spec: Mapped[dict] = mapped_column(JSON, nullable=False) sha256: Mapped[str] = mapped_column(Unicode(255), unique=True, nullable=False) + # TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped created_on: Mapped[datetime.datetime] = mapped_column( DateTime, default=datetime.datetime.utcnow ) @@ -206,6 +207,7 @@ class Solve(Base): specification: Mapped["Specification"] = relationship(back_populates="solves") scheduled_on: Mapped[datetime.datetime] = mapped_column( + # TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped DateTime, default=datetime.datetime.utcnow ) started_on: Mapped[datetime.datetime] = mapped_column(DateTime, default=None) @@ -259,6 +261,7 @@ class Build(Base): status_info: Mapped[str] = mapped_column(UnicodeText, default=None) size: Mapped[int] = mapped_column(BigInteger, default=0) scheduled_on: Mapped[datetime.datetime] = mapped_column( + # TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped DateTime, default=datetime.datetime.utcnow ) started_on: Mapped[datetime.datetime] = mapped_column(DateTime, default=None) @@ -721,6 +724,7 @@ def update_packages(self, db, subdirs=None): logger.info(f"DONE for architecture : {architecture}") + # TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped self.last_update = datetime.datetime.utcnow() db.commit() logger.info("update packages DONE ") diff --git a/conda-store-server/conda_store_server/_internal/schema.py b/conda-store-server/conda_store_server/_internal/schema.py index 0282a5565..56e404528 100644 --- a/conda-store-server/conda_store_server/_internal/schema.py +++ b/conda-store-server/conda_store_server/_internal/schema.py @@ -25,6 +25,7 @@ def _datetime_factory(offset: datetime.timedelta): """Utcnow datetime + timezone as string""" + # TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped return datetime.datetime.utcnow() + offset diff --git a/conda-store-server/conda_store_server/_internal/worker/build.py b/conda-store-server/conda_store_server/_internal/worker/build.py index 0fa92a43f..9216c7210 100644 --- a/conda-store-server/conda_store_server/_internal/worker/build.py +++ b/conda-store-server/conda_store_server/_internal/worker/build.py @@ -73,6 +73,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 + # TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped build.started_on = datetime.datetime.utcnow() db.commit() @@ -82,6 +83,7 @@ def set_build_failed( ): build.status = schema.BuildStatus.FAILED build.status_info = status_info + # TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped build.ended_on = datetime.datetime.utcnow() db.commit() @@ -91,12 +93,14 @@ def set_build_canceled( ): build.status = schema.BuildStatus.CANCELED build.status_info = status_info + # TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped build.ended_on = datetime.datetime.utcnow() db.commit() def set_build_completed(db: Session, conda_store, build: orm.Build): build.status = schema.BuildStatus.COMPLETED + # TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped build.ended_on = datetime.datetime.utcnow() directory_build_artifact = orm.BuildArtifact( @@ -156,6 +160,7 @@ def build_cleanup( builds = api.list_builds(db, status=schema.BuildStatus.BUILDING) for build in builds: + # TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped if ( build.status == schema.BuildStatus.BUILDING and str(build.id) not in build_active_tasks @@ -193,6 +198,7 @@ def build_conda_environment(db: Session, conda_store, build): db, conda_store, build, + # TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped f"starting build of conda environment {datetime.datetime.utcnow()} UTC\n", ) @@ -337,6 +343,7 @@ def build_conda_environment(db: Session, conda_store, build): def solve_conda_environment(db: Session, conda_store, solve: orm.Solve): + # TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped solve.started_on = datetime.datetime.utcnow() db.commit() @@ -353,6 +360,7 @@ def solve_conda_environment(db: Session, conda_store, solve: orm.Solve): solve_id=solve.id, ) + # TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped solve.ended_on = datetime.datetime.utcnow() db.commit() diff --git a/conda-store-server/conda_store_server/app.py b/conda-store-server/conda_store_server/app.py index 8150da920..38be65070 100644 --- a/conda-store-server/conda_store_server/app.py +++ b/conda-store-server/conda_store_server/app.py @@ -817,6 +817,7 @@ def delete_namespace(self, db: Session, namespace: str): if namespace is None: raise utils.CondaStoreError(f"namespace={namespace} does not exist") + # TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped utcnow = datetime.datetime.utcnow() namespace.deleted_on = utcnow for environment_orm in namespace.environments: @@ -846,6 +847,7 @@ def delete_environment(self, db: Session, namespace: str, name: str): f"environment namespace={namespace} name={name} does not exist" ) + # TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped utcnow = datetime.datetime.utcnow() environment.deleted_on = utcnow for build in environment.builds: @@ -877,6 +879,7 @@ def delete_build(self, db: Session, build_id: int): "cannot delete build since not finished building" ) + # TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped build.deleted_on = datetime.datetime.utcnow() db.commit() diff --git a/conda-store-server/conda_store_server/server/auth.py b/conda-store-server/conda_store_server/server/auth.py index c042f94f9..bf56db086 100644 --- a/conda-store-server/conda_store_server/server/auth.py +++ b/conda-store-server/conda_store_server/server/auth.py @@ -561,6 +561,7 @@ async def post_login_method( samesite="strict", domain=self.cookie_domain, # set cookie to expire at same time as jwt + # TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped max_age=int( (authentication_token.exp - datetime.datetime.utcnow()).total_seconds() ), diff --git a/conda-store-server/tests/conftest.py b/conda-store-server/tests/conftest.py index f1cebe23b..90aa0ab31 100644 --- a/conda-store-server/tests/conftest.py +++ b/conda-store-server/tests/conftest.py @@ -158,6 +158,7 @@ def seed_conda_store(db, conda_store): # for testing purposes make build 4 complete build = api.get_build(db, build_id=4) + # TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped build.started_on = datetime.datetime.utcnow() build.ended_on = datetime.datetime.utcnow() build.status = schema.BuildStatus.COMPLETED diff --git a/conda-store-server/tests/server/test_auth.py b/conda-store-server/tests/server/test_auth.py index 015aa4d68..f0c3ed6a8 100644 --- a/conda-store-server/tests/server/test_auth.py +++ b/conda-store-server/tests/server/test_auth.py @@ -77,6 +77,7 @@ def test_expired_token(): token = authentication.encrypt_token( AuthenticationToken( primary_namespace="default", + # TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped exp=datetime.datetime.utcnow() - datetime.timedelta(hours=1), role_bindings={ "default/*": ["viewer"],