From f6d455049c1d13f1e92c672ddaf5b5c16ecb4c50 Mon Sep 17 00:00:00 2001 From: Derek Fitchett <135860892+dfitchett@users.noreply.github.com> Date: Fri, 1 Mar 2024 16:09:41 -0800 Subject: [PATCH] EP Merge: Fixed issue with created_at being incorrectly set. (#2695) Fixed issue with created_at being incorrectly set. --- .../src/python_src/model/merge_job.py | 5 ++--- .../src/python_src/schema/merge_job.py | 13 ++++++++----- .../src/python_src/service/ep_merge_machine.py | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/domain-ee/ee-ep-merge-app/src/python_src/model/merge_job.py b/domain-ee/ee-ep-merge-app/src/python_src/model/merge_job.py index 305ce3eef2..ee5a62756d 100644 --- a/domain-ee/ee-ep-merge-app/src/python_src/model/merge_job.py +++ b/domain-ee/ee-ep-merge-app/src/python_src/model/merge_job.py @@ -3,7 +3,6 @@ from sqlalchemy import Column, DateTime, Integer, String from sqlalchemy.dialects.postgresql import ARRAY, JSONB, UUID from sqlalchemy.ext.mutable import MutableDict -from sqlalchemy.sql import func class MergeJob(Base): @@ -16,5 +15,5 @@ class MergeJob(Base): state = Column(String, index=True) error_state = Column(String) messages = Column(ARRAY(MutableDict.as_mutable(JSONB))) - created_at = Column(DateTime, default=func.now()) - updated_at = Column(DateTime, default=func.now(), onupdate=func.now()) + created_at = Column(DateTime) + updated_at = Column(DateTime) diff --git a/domain-ee/ee-ep-merge-app/src/python_src/schema/merge_job.py b/domain-ee/ee-ep-merge-app/src/python_src/schema/merge_job.py index 948199be5b..ceec934086 100644 --- a/domain-ee/ee-ep-merge-app/src/python_src/schema/merge_job.py +++ b/domain-ee/ee-ep-merge-app/src/python_src/schema/merge_job.py @@ -4,8 +4,7 @@ from uuid import UUID import model.merge_job -from pydantic import BaseModel, ConfigDict, conint -from typing_extensions import ClassVar +from pydantic import BaseModel, ConfigDict, conint, Field from util.custom_enum import StrEnum @@ -38,7 +37,6 @@ def __str__(self): class MergeJob(BaseModel): - _init_time: ClassVar[datetime] = datetime.now() job_id: UUID pending_claim_id: conint(strict=True) @@ -46,8 +44,13 @@ class MergeJob(BaseModel): state: JobState = JobState.PENDING error_state: JobState | None = None messages: list[Any] | None = None - created_at: datetime = _init_time - updated_at: datetime = _init_time + created_at: datetime = Field(default_factory=datetime.now) + updated_at: datetime = None + + def __init__(self, *args, **kwargs) -> None: + super().__init__(*args, **kwargs) + if not self.updated_at: + self.updated_at = self.created_at model_config = ConfigDict(from_attributes=True) diff --git a/domain-ee/ee-ep-merge-app/src/python_src/service/ep_merge_machine.py b/domain-ee/ee-ep-merge-app/src/python_src/service/ep_merge_machine.py index 0fbf62632d..366f7507df 100644 --- a/domain-ee/ee-ep-merge-app/src/python_src/service/ep_merge_machine.py +++ b/domain-ee/ee-ep-merge-app/src/python_src/service/ep_merge_machine.py @@ -279,7 +279,7 @@ def on_completed(self, event): f"job_id={self.job.job_id} " f"pending_claim_id={self.job.pending_claim_id} " f"ep400_claim_id={self.job.ep400_claim_id} " - f"state={self.job.state}" + f"state={self.job.state} " f"job_duration_seconds={job_duration}" )